home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / shdk-1.zip / SKYHAWK.DOC < prev    next >
Text File  |  1992-03-25  |  166KB  |  6,450 lines

  1.  
  2.  
  3.  
  4.                          THE SKYHAWK DEVELOPMENT LIBRARY
  5.  
  6.                                         by
  7.  
  8.                                    Bill Madison
  9.  
  10.                         W. G. Madison and Associates, Ltd.
  11.                                13819 Shavano Downs
  12.                                  P.O. Box 780956
  13.                             San Antonio, TX 78278-0956
  14.                                   (512)492-2777
  15.                                   CIS 73240,342
  16.  
  17.                        Copyright 1992 Madison & Associates
  18.                                All Rights Reserved
  19.  
  20.  
  21.                                TERMS AND CONDITIONS
  22.  
  23.              This collection of units with the associated TEST*.*
  24.              files and this .DOC file may be freely used, copied,
  25.              and distributed for non-commercial use, provided only
  26.              that no fee is charged for the package beyond a nominal
  27.              copying charge, and provided that the entire package is
  28.              distributed IN UNALTERED FORM. The sole exception to
  29.              this latter restriction is that bona-fide computer
  30.              clubs and user groups may append text material to the
  31.              documentation file, provided that any material so
  32.              appended is clearly identified as to its source, its
  33.              beginning, and its end.
  34.  
  35.              While no registration or other fee is charged for the
  36.              non-commercial use of the collection, we will willingly
  37.              accept contributions from those wishing to support our
  38.              work. An amount of $10.00 is suggested. Checks should
  39.              be made out to W. G. Madison and Associates, Ltd., and
  40.              forwarded to the above address.
  41.  
  42.              Those wishing to use the SkyHawk collection for commer-
  43.              cial purposes should contact Madison & Associates at
  44.              the above address to arrange terms.
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.                                         i
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.                                      PREFACE
  66.  
  67.              The Cessna SkyHawk is a small single engine airplane. It is
  68.         also the airplane in which I learned to fly. On the day of my
  69.         first solo flight, I felt as the poet must have when he wrote:
  70.  
  71.                      Up, up the long delirious burning blue,
  72.                I've topped the wind-swept heights with easy grace,
  73.                        Where never lark or even eagle flew
  74.                   And while with silent uplifting mind I've trod
  75.                     The high, untrespassed sanctity of space,
  76.                    Put out my hand and touched the face of God!
  77.  
  78.                                                 John Gillespie Magee, Jr.
  79.                                                             "High Flight"
  80.  
  81.  
  82.              As the SkyHawk Development Library was being written and
  83.         began to be used at Madison and Associates, we found that we felt
  84.         somewhat the same sense of freedom and mastery of the environment
  85.         when using the library as that which I had felt during my first
  86.         solo. We sincerely hope that you will share these feelings with
  87.         us.
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.                                         ii
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.                                   INTRODUCTION
  124.  
  125.              The SkyHawk Development Library is a collection of units
  126.         compilable under Borland's Turbo PASCAL 5 and above. Some of the
  127.         functionalities are to be found in other collections but are re-
  128.         implemented here in an extended form or to provide a different
  129.         approach. Some are unique to the SkyHawk collection. All are pro-
  130.         vided with the goal of removing the necessity of "reinventing the
  131.         wheel" during the development process.
  132.  
  133.              The collection is dynamic, in the sense that it is being
  134.         constantly augmented by the addition of new units and the im-
  135.         provement of the existing ones. We welcome all suggestions for
  136.         additional units and/or routines, bug reports, and general com-
  137.         ments. Just drop us a note at the address above. Or call us
  138.         (9:00am - 5:00pm Central time) or drop us an EMAIL message on
  139.         CompuServe using the CIS address shown.
  140.  
  141.              The SkyHawk collection depends on the TurboProfessional 5.0
  142.         library from TurboPower Software. Most of the units were initial-
  143.         ly developed while we were working on a series of projects for
  144.         which conversion to an object oriented design was not economical-
  145.         ly feasible. Thus the dependence on TurboProfessional rather than
  146.         ObjectProfessional. In most cases, however, you will find that
  147.         conversion to object oriented code will be trivial. When time
  148.         permits, Madison & Associates intends to convert the entire
  149.         collection to objects and to provide both.
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.                                        iii
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.                              WHAT'S IN THE LIBRARY?
  182.  
  183.         ____________________________
  184.         SHCLRDEF
  185.              ShClrDef is a unit which is serves two functions;
  186.  
  187.             *  It defines constants such that each normally allowable
  188.                combination of text forground and background colors can be
  189.                specified by name; e.g., YellowOnBlack, MagentaOnLtGray.
  190.  
  191.             *  It interfaces a function which displays a "screen selec-
  192.                tion panel", allowing the user to move a special cursor to
  193.                a desired forground/background color combination and then
  194.                select that combination by pressing <Ret>, returning the
  195.                attribute value. This function is particularly useful in
  196.                the construction of installation programs. The end user
  197.                can be permitted to select color combinations for any par-
  198.                ticular screen element, which can then be displayed.
  199.  
  200.              Additionally, a function is interfaced which, given an
  201.         attribute value as input, returns a string containing the
  202.         attribute name; e.g.,
  203.  
  204.                                   ColorName($1E)
  205.  
  206.         returns 'YellowOnBlue'.
  207.  
  208.  
  209.         ____________________________
  210.         SHCMDLIN
  211.              Developers of command line driven programs constantly face
  212.         the problem of providing acceptable levels of syntax flexibility
  213.         on the command line coupled with a minimum level of labor in
  214.         coding the command line analyzer. This unit, ShCmdLin, removes
  215.         all of the heartburn associated with the coding, while providing
  216.         a maximum level of syntactic flexibility to the user.
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.                                         iv
  233.  
  234.  
  235.  
  236.         ____________________________
  237.         SHCMPLX
  238.              ShCmplx is a complex arithmetic unit. It provides for the
  239.         basic binary arithmetic functions (addition, subtraction, multi-
  240.         plication, division), plus the raising of a complex number to a
  241.         real power. Conversion functions are provided to convert between
  242.         a complex number represented in Cartesian form and one repre-
  243.         sented in polar form. Finally, provision is made to convert a
  244.         complex number in Cartesian form to a string; or a complex in
  245.         polar form to a string expressing the angle either in degrees or
  246.         in radians.
  247.  
  248.  
  249.         ____________________________
  250.         SHCRCCHK
  251.              When the DOS COPY command is used, no true read-after-write
  252.         verification is performed. The only way to assure that the re-
  253.         cording was correct is to read the file after writing, and com-
  254.         pare the output file, byte for byte, with the input. For very
  255.         long files this can result in unacceptable delays.
  256.  
  257.              A reasonable compromise between speed and reliability is to
  258.         calculate the cyclic redundancy check (CRC) word of the input
  259.         file as it is being copied, and then on completion of the copying
  260.         operation, read back the output file and calculate its CRC. If
  261.         the two compare and the files are of the same size, the probabil-
  262.         ity that the two files differ is extremely small.
  263.  
  264.              ShCrcChk is a unit which interfaces two functions, both of
  265.         which calculate the CRC16 of a file whose name is provided as a
  266.         string parameter. One of the functions simply calculates the CRC
  267.         and returns it; the other in addition copies the input file to
  268.         another file whose name is provided as a second string parameter.
  269.  
  270.  
  271.         ____________________________
  272.         SHERRMSG
  273.              ShErrMsg is a unit which installs an exit procedure in Turbo
  274.         PASCAL programs. This exit procedure displays a short explanatory
  275.         message whenever a program terminates abnormally; whenever it re-
  276.         turns to DOS with a return code other than zero.
  277.  
  278.              It also interfaces replacements for the HALT and RUNERROR
  279.         procedures in Turbo PASCAL's SYSTEM unit. These procedures per-
  280.         form functions not provided by PASCAL's normal termination
  281.         procedures.
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.                                         v
  291.  
  292.  
  293.  
  294.         ____________________________
  295.         SHLIST
  296.              Lists, rings, and stacks are among the most common data
  297.         structures used (after arrays). They are also probably among the
  298.         worst offenders when it comes to "re-inventing the wheel." Many
  299.         programmers build special purpose list manipulation routines each
  300.         time a list is needed. Obviously, a generic list manipulation
  301.         package is a valuable addition to the available "bag of tricks."
  302.  
  303.              ShList contains all of the routines necessary to establish
  304.         and manipulate singly and doubly linked lists, rings, and stacks.
  305.         The data associated with any given list, ring, or stack can be
  306.         any standard or user defined data type. The structure of the data
  307.         can change, but the total length of the data must remain con-
  308.         stant. Thus, for example, variant records can be used.
  309.  
  310.  
  311.         ____________________________
  312.         SHLNGSTR
  313.              ShLngStr is a unit which provides the ability to manipulate
  314.         long strings (up to 65517 characters in length) using Turbo
  315.         PASCAL.
  316.  
  317.              ShLngStr stores all of its string data on the heap. When a
  318.         variable is declared to be of type LongString, this declaration
  319.         establishes only a pointer in the data segment. The LongString
  320.         must then be initialized prior to use. This initialization estab-
  321.         lishes a maximum allowable string length, which may now vary from
  322.         one LongString to the next. Only the amount of heap space requir-
  323.         ed for the initialized maximum length is used. In this respect,
  324.         the analog of a string declaration of, for example, "var
  325.         string[127];" has been preserved. Any of the procedures and
  326.         functions in this unit will observe the "declared" maximum
  327.         length, and will adjust their behavior appropriately.
  328.  
  329.  
  330.         ____________________________
  331.         SHUTILPK
  332.              ShUtilPk is a collection of miscellaneous utility proce-
  333.         dures, generally lower level than those in the other units of
  334.         this collection.
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.                                         vi
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.                                 UNIT DEPENDENCIES
  356.  
  357.              As mentioned above, the SkyHawk collection is dependent upon
  358.         the TurboProfessional-5.0 library published by TurboPower Soft-
  359.         ware. There are also dependencies within the SkyHawk collection
  360.         itself. The following matrix shows these dependencies.
  361.  
  362.  
  363.                                  D  S  S  T  T  T  T  T  T
  364.                                  O  H  H  P  P  P  P  P  P
  365.                                  S  L  U  C  D  I  M  S  W
  366.                                  |  I  T  R  O  N  E  T  I
  367.                       +--uses--> |  S  I  T  S  L  M  R  N
  368.                       |          |  T  L  |  |  I  C  I  D
  369.                       |          |  |  P  |  |  N  H  N  O
  370.                       |          |  |  K  |  |  E  K  G  W
  371.                       |          |  |  |  |  |  |  |  |  |
  372.                       ShClrDef   -  -  -  X  -  -  -  -  X
  373.                       ShCmdLin   X  X  X  -  -  -  -  -  -
  374.                       ShCmplx    -  -  -  -  -  -  -  -  -
  375.                       ShCrcChk   X  -  -  -  -  -  -  -  -
  376.                       ShDatPk    X  -  -  -  -  -  -  -  -
  377.                       ShErrMsg   -  -  -  -  -  -  -  -  -
  378.                       ShList     -  -  -  -  -  X  X  X  -
  379.                       ShLngStr   -  -  -  -  -  X  X  X  -
  380.                       ShUtilPk   -  -  -  -  X  -  -  X  -
  381.  
  382.                              Unit Dependencies Matrix
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.                                        vii
  407.                                                          03/25/92 01:54pm
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.                        This page has been deliberately left
  430.                          blank, except for this message.
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.                                        viii
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.                                     ShClrDef
  473.  
  474.                              A Color Definition Unit
  475.  
  476.  
  477.  
  478.         INTRODUCTION
  479.              ShClrDef is a unit which serves two functions;
  480.  
  481.             *  It defines constants such that each normally allowable
  482.                combination of text forground and background colors can be
  483.                specified by name; e.g., YellowOnBlack, MagentaOnLtGray.
  484.  
  485.             *  It interfaces a function which displays a "screen selec-
  486.                tion panel", allowing the user to move a special cursor to
  487.                a desired forground/background color combination and then
  488.                select that combination by pressing <Ret>. The attribute
  489.                value is returned.
  490.  
  491.              Additionally, a function is interfaced which, given an
  492.         attribute value as input, returns a string containing the
  493.         attribute name; e.g.,
  494.  
  495.                                   ColorName($1E)
  496.  
  497.         returns 'YellowOnBlue'.
  498.  
  499.  
  500.         INTERFACED ELEMENTS
  501.  
  502.         Constants
  503.         =========
  504.              {Black text}                    {Blue text}
  505.              BlackOnBlack       = $00;       BlueOnBlack        = $01;
  506.              BlackOnBlue        = $10;       BlueOnBlue         = $11;
  507.              BlackOnGreen       = $20;       BlueOnGreen        = $21;
  508.              BlackOnCyan        = $30;       BlueOnCyan         = $31;
  509.              BlackOnRed         = $40;       BlueOnRed          = $41;
  510.              BlackOnMagenta     = $50;       BlueOnMagenta      = $51;
  511.              BlackOnBrown       = $60;       BlueOnBrown        = $61;
  512.              BlackOnLtGray      = $70;       BlueOnLtGray       = $71;
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.                                   ShClrDef  1-1
  524.  
  525.  
  526.  
  527.              {Green text}                    {Cyan text}
  528.              GreenOnBlack       = $02;       CyanOnBlack        = $03;
  529.              GreenOnBlue        = $12;       CyanOnBlue         = $13;
  530.              GreenOnGreen       = $22;       CyanOnGreen        = $23;
  531.              GreenOnCyan        = $32;       CyanOnCyan         = $33;
  532.              GreenOnRed         = $42;       CyanOnRed          = $43;
  533.              GreenOnMagenta     = $52;       CyanOnMagenta      = $53;
  534.              GreenOnBrown       = $62;       CyanOnBrown        = $63;
  535.              GreenOnLtGray      = $72;       CyanOnLtGray       = $73;
  536.  
  537.              {Red text}                      {Magenta text}
  538.              RedOnBlack         = $04;       MagentaOnBlack     = $05;
  539.              RedOnBlue          = $14;       MagentaOnBlue      = $15;
  540.              RedOnGreen         = $24;       MagentaOnGreen     = $25;
  541.              RedOnCyan          = $34;       MagentaOnCyan      = $35;
  542.              RedOnRed           = $44;       MagentaOnRed       = $45;
  543.              RedOnMagenta       = $54;       MagentaOnMagenta   = $55;
  544.              RedOnBrown         = $64;       MagentaOnBrown     = $65;
  545.              RedOnLtGray        = $74;       MagentaOnLtGray    = $75;
  546.  
  547.              {Brown text}                    {Light Gray text}
  548.              BrownOnBlack       = $06;       LtGrayOnBlack      = $07;
  549.              BrownOnBlue        = $16;       LtGrayOnBlue       = $17;
  550.              BrownOnGreen       = $26;       LtGrayOnGreen      = $27;
  551.              BrownOnCyan        = $36;       LtGrayOnCyan       = $37;
  552.              BrownOnRed         = $46;       LtGrayOnRed        = $47;
  553.              BrownOnMagenta     = $56;       LtGrayOnMagenta    = $57;
  554.              BrownOnBrown       = $66;       LtGrayOnBrown      = $67;
  555.              BrownOnLtGray      = $76;       LtGrayOnLtGray     = $77;
  556.  
  557.              {Dark Gray text}                {Light Blue text}
  558.              DkGrayOnBlack      = $08;       LtBlueOnBlack      = $09;
  559.              DkGrayOnBlue       = $18;       LtBlueOnBlue       = $19;
  560.              DkGrayOnGreen      = $28;       LtBlueOnGreen      = $29;
  561.              DkGrayOnCyan       = $38;       LtBlueOnCyan       = $39;
  562.              DkGrayOnRed        = $48;       LtBlueOnRed        = $49;
  563.              DkGrayOnMagenta    = $58;       LtBlueOnMagenta    = $59;
  564.              DkGrayOnBrown      = $68;       LtBlueOnBrown      = $69;
  565.              DkGrayOnLtGray     = $78;       LtBlueOnLtGray     = $79;
  566.  
  567.              {Light Green Text}              {Light Cyan text}
  568.              LtGreenOnBlack     = $0A;       LtCyanOnBlack      = $0B;
  569.              LtGreenOnBlue      = $1A;       LtCyanOnBlue       = $1B;
  570.              LtGreenOnGreen     = $2A;       LtCyanOnGreen      = $2B;
  571.              LtGreenOnCyan      = $3A;       LtCyanOnCyan       = $3B;
  572.              LtGreenOnRed       = $4A;       LtCyanOnRed        = $4B;
  573.              LtGreenOnMagenta   = $5A;       LtCyanOnMagenta    = $5B;
  574.              LtGreenOnBrown     = $6A;       LtCyanOnBrown      = $6B;
  575.              LtGreenOnLtGray    = $7A;       LtCyanOnLtGray     = $7B;
  576.  
  577.  
  578.  
  579.  
  580.  
  581.                                   ShClrDef  1-2
  582.  
  583.  
  584.  
  585.              {Light Red text}                {Light Magenta text}
  586.              LtRedOnBlack       = $0C;       LtMagentaOnBlack   = $0D;
  587.              LtRedOnBlue        = $1C;       LtMagentaOnBlue    = $1D;
  588.              LtRedOnGreen       = $2C;       LtMagentaOnGreen   = $2D;
  589.              LtRedOnCyan        = $3C;       LtMagentaOnCyan    = $3D;
  590.              LtRedOnRed         = $4C;       LtMagentaOnRed     = $4D;
  591.              LtRedOnMagenta     = $5C;       LtMagentaOnMagenta = $5D;
  592.              LtRedOnBrown       = $6C;       LtMagentaOnBrown   = $6D;
  593.              LtRedOnLtGray      = $7C;       LtMagentaOnLtGray  = $7D;
  594.  
  595.              {Yellow text}                   {White text}
  596.              YellowOnBlack      = $0E;       WhiteOnBlack       = $0F;
  597.              YellowOnBlue       = $1E;       WhiteOnBlue        = $1F;
  598.              YellowOnGreen      = $2E;       WhiteOnGreen       = $2F;
  599.              YellowOnCyan       = $3E;       WhiteOnCyan        = $3F;
  600.              YellowOnRed        = $4E;       WhiteOnRed         = $4F;
  601.              YellowOnMagenta    = $5E;       WhiteOnMagenta     = $5F;
  602.              YellowOnBrown      = $6E;       WhiteOnBrown       = $6F;
  603.              YellowOnLtGray     = $7E;       WhiteOnLtGray      = $7F;
  604.  
  605.  
  606.  
  607.         Types
  608.         =====
  609.              Orientation = (Vertical, Horizontal);
  610.  
  611.              Determines whether the color selection panel displayed by
  612.         SelectColors is presented with its long dimension oriented
  613.         vertically or horizontally on the screen.
  614.  
  615.  
  616.         Routines
  617.         ========
  618.         ____________________________
  619.         SELECTCOLORS
  620.  
  621.         Declaration:
  622.              function SelectColors(Row, Col, BegAttr : byte;
  623.                               CpFrameChars      : FrameArray;
  624.                               Orient            : Orientation;
  625.                               ErasePanelOnExit,
  626.                               EraseCursorOnExit,
  627.                               WrapCursor        : boolean;
  628.                               Header  : string) : byte;
  629.  
  630.  
  631.         Purpose:
  632.              Displays a color selection panel, permitting the user to
  633.         move a special cursor using the arrow keys and select a desired
  634.         color combination using the <CR> key.
  635.  
  636.  
  637.  
  638.  
  639.                                   ShClrDef  1-3
  640.  
  641.  
  642.  
  643.         Comments:
  644.              The user navigates the panel with the arrow keys and selects
  645.         the desired color combination by pressing <CR>. The attribute
  646.         byte value currently under the cursor will be returned. The user
  647.         can also press <INS>, which will return a function value of $FF,
  648.         and by convention, should be taken to indicate that the currently
  649.         selected attribute value is to be unchanged. Additionally, the
  650.         user can press <ESC>, returning a function value of $FE, which by
  651.         convention should be taken to indicate that the current color
  652.         selection run is completed. Finally, a return of $FD indicates
  653.         that the user has pressed the <F1> key either alone or in
  654.         combination with one of the shift-type keys (<L-SHIFT>, <R-
  655.         SHIFT>, <CTRL>, or <ALT>), and by convention indicates that the
  656.         user is requesting help.
  657.  
  658.              The function performs the following actions:
  659.  
  660.             *  Displays a 16x8 panel of text colors with the window
  661.                coordinates of the upper left corner at coordinates X=Col,
  662.                Y=Row.
  663.  
  664.             *  The attribute at which the cursor will be initially placed
  665.                is at BegAttr.
  666.  
  667.             *  The color panel will be framed using the characters
  668.                specified in CpFrameChars.
  669.  
  670.             *  The orientation of the long dimension of the selection
  671.                panel is determined as specified by Orient.
  672.  
  673.             *  ErasePanelOnExit determines whether the panel is erased or
  674.                preserved on the screen when SelectColors returns to the
  675.                caller. The panel is always disposed, and its heap space
  676.                reclaimed.
  677.  
  678.             *  EraseCursorOnExit is only effective if ErasePanelOnExit is
  679.                false. If the panel is to be preserved between calls to
  680.                SelectColors, EraseCursor determines whether the or not
  681.                the cursor will continue to be displayed along with the
  682.                panel.
  683.  
  684.             *  WrapCursor determines whether the cursor will wrap both
  685.                horizontally and vertically. True allows the cursor to
  686.                wrap; False inhibits further cursor movement when a window
  687.                edge is reached.
  688.  
  689.             *  Header is the header line which will be displayed on the
  690.                panel. It can be supplied as an empty string (''), in
  691.                which case no header will be displayed.
  692.  
  693.  
  694.  
  695.  
  696.  
  697.                                   ShClrDef  1-4
  698.  
  699.  
  700.  
  701.             *  The function returns a normal text attribute byte, with
  702.                the following exceptions:
  703.  
  704.                Return         Explanation
  705.                ------         -----------
  706.                $FF            <INS> was pressed by the user. Leave the
  707.                              current value unchanged.
  708.                $FE            <ESC> was pressed by the user. Accept all
  709.                              current values and consider the run
  710.                              completed.
  711.                $FD            <F1> was pressed by the user. Provide a
  712.                              HELP screen or message.
  713.                $F0            Error in MakeWindow
  714.                $F1            Error in DisplayWindow
  715.  
  716.         ____________________________
  717.         COLORNAME
  718.  
  719.         Declaration:
  720.              function ColorName(Attr  : byte) : string;
  721.  
  722.         Purpose:
  723.              Given a text attribute byte, ColorName returns the attribute
  724.         color name as defined above; e.g., ColorName($1E) will return
  725.         'YellowOnBlue'.
  726.  
  727.         Comment:
  728.              If a byte value is passed which does not correspond to a
  729.         valid text attribute, an empty string is returned.
  730.  
  731.         Example:
  732.         The statement
  733.  
  734.                              WriteLn(ColorName($73));
  735.  
  736.         displays the string
  737.  
  738.                                    CyanOnLtGray
  739.  
  740.         on the screen.
  741.  
  742.  
  743.  
  744.  
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755.                                   ShClrDef  1-5
  756.                                                          03/25/92 01:54pm
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.                        This page has been deliberately left
  779.                          blank, except for this message.
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.                                   ShClrDef  1-6
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.                                     ShCmdLin
  822.  
  823.                            A Command Line Parsing Unit
  824.  
  825.  
  826.         INTRODUCTION
  827.              Developers of command line driven programs constantly face
  828.         the problem of providing acceptable levels of syntax flexibility
  829.         on the command line coupled with a minimum level of labor in
  830.         coding the command line analyzer. This unit, ShCmdLin, removes
  831.         all of the heartburn associated with the coding, while providing
  832.         a maximum level of syntactic flexibility to the user.
  833.  
  834.              ShCmdLin contains all those routines necessary not only to
  835.         parse the command line but also to determine the current DOS
  836.         switch lead-in character and, if desired, change it. Further, the
  837.         parsing routine allows a set of characters (rather than just a
  838.         single character) to be defined as acceptable for switch lead-in.
  839.         It further permits a set of characters to serve as the switch
  840.         value lead-in. Thus, for example, one could use ['/','-'] for
  841.         switch lead-in, and [':','='] for value lead-in. This would have
  842.         the effect of making the following two command tails functionally
  843.         identical:
  844.  
  845.                      /Alpha-Bravo=27.9-Charlie:14/Delta=Echo
  846.                      -Alpha/Bravo:27.9/Charlie=14-Delta:Echo
  847.  
  848.              For each switch, the parsing routine prepares one variant
  849.         record (see below, the definition of the SwRec type) and appends
  850.         it to a list, from which it may be retrieved as required. Apply-
  851.         ing this to the example above, the following will be true.
  852.  
  853.              In each case in the example, the NAME of the first switch is
  854.         Alpha, and it has no assigned value (switches lacking an assigned
  855.         value will be returned as a string-type, but with an empty string
  856.         as the value); the NAME of the second switch is Bravo and it has
  857.         a real-type value of 27.9; the NAME of the third is Charlie and
  858.         it has an integer-type value of 14; and the NAME of the fourth is
  859.         Delta and it has a string-type value of 'Echo'.
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.  
  869.  
  870.  
  871.  
  872.                                   ShCmdLin  2-1
  873.  
  874.  
  875.  
  876.                                !!CAUTIONARY NOTE!!
  877.  
  878.              The characters ^C (<ETX> or #3), ^M (<CR> or #13), and
  879.              ^[ (<ESC> or #27) cannot be embedded in a command tail.
  880.              The parser, however, can be used to parse arbitrary
  881.              strings; not just command tails. THESE ARBITRARY
  882.              STRINGS MUST NOT CONTAIN ANY OF THE THREE INDICATED
  883.              CHARACTERS. These characters are RESERVED for internal
  884.              use by the parser.
  885.  
  886.                            !!END OF CAUTIONARY NOTE!!
  887.  
  888.  
  889.                                !!CAUTIONARY NOTE!!
  890.  
  891.              MARK/RELEASE must not be used for heap management when
  892.              using this unit. GETMEM/FREEMEM or NEW/DISPOSE must be
  893.              used instead.
  894.  
  895.                            !!END OF CAUTIONARY NOTE!!
  896.  
  897.  
  898.         INTERFACED ELEMENTS
  899.  
  900.         Types
  901.         =====
  902.              ValueType = (VtStr, VtReal, VtInt);
  903.              SwRec     = record
  904.                            Name  : string;
  905.                            case SwVal  : ValueType of
  906.                              VtStr : (StrVal : string);
  907.                              VtReal: (RealVal: Extended);
  908.                              VtInt : (IntVal : integer);
  909.                            end; {SwRec}
  910.              CharSet = Set of Char;
  911.  
  912.              If you do not have a math coprocessor and do not want to pay
  913.         the space and time overhead required for coprocessor emulation,
  914.         you may wish to change the VtReal variant in the definition of
  915.         SwRec from type Extended to type Real.
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.                                   ShCmdLin  2-2
  931.  
  932.  
  933.  
  934.         Routines
  935.         ========
  936.         ____________________________
  937.         CLCLOSE
  938.  
  939.         Declaration:
  940.              procedure ClClose;
  941.  
  942.         Purpose:
  943.              Closes the internal data structures and frees the space
  944.         associated with the command line switch list.
  945.  
  946.         Comments:
  947.              If GetSwitch is used to retrieve switch values, ClClose
  948.         should be called following retrieval of the last switch. If
  949.         PopSwitch is used, ClClose need not be called.
  950.  
  951.         Examples:
  952.              See the files TESTCL.PAS and CLTEST.BAT
  953.  
  954.         See also:
  955.              ClInit    GetSwitch      PopSwitch
  956.  
  957.  
  958.         ____________________________
  959.         CLINIT
  960.  
  961.         Declaration:
  962.              procedure ClInit;
  963.  
  964.         Purpose:
  965.              Initializes the internal data structures used to store the
  966.         command line switch list.
  967.  
  968.         Comments:
  969.              ClInit MUST be called prior to any of the other Cl routines.
  970.  
  971.         Examples:
  972.              See the files TESTCL.PAS and CLTEST.BAT
  973.  
  974.         See also:
  975.              ClClose
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.                                   ShCmdLin  2-3
  989.  
  990.  
  991.  
  992.         ____________________________
  993.         CLPARSE
  994.  
  995.         Declaration:
  996.              procedure ClParse(StrPtr : Pointer; StrOnly : Boolean;
  997.                       LeadIn, ValDelim : CharSet; var Err : Integer);
  998.  
  999.         Purpose:
  1000.              To parse a command tail (or other string of similar form),
  1001.         producing a list of switch names and associated values which can
  1002.         then be retrieved using the GetSwitch or PopSwitch functions.
  1003.  
  1004.         Comments:
  1005.              Parsing is accomplished by invoking the procedure ClParse
  1006.         with five parameters:
  1007.  
  1008.            1.  StrPtr of type Pointer is used to point to the string to
  1009.                be parsed. If StrPtr is NIL, the command tail will be
  1010.                parsed.
  1011.  
  1012.            2.  StrOnly of type Boolean is used to determine if switch
  1013.                values of type String are to be forced, regardless of the
  1014.                form of the value. StrOnly = True forces String values.
  1015.  
  1016.            3.  LeadIn of type CharSet is used to identify the set of
  1017.                characters used to mark the beginning of a switch. It is
  1018.                suggested that LeadIn be set to [ ReadSwCh ]. The weakest
  1019.                condition used should be that the expression ( ReadSwCh in
  1020.                LeadIn ) be TRUE.
  1021.  
  1022.            4.  ValDelim of type CharSet is used to specify the set of
  1023.                characters which may be used to separate the switch name
  1024.                from the switch value.
  1025.  
  1026.            5.  Err of type Integer is used to return error conditions.
  1027.  
  1028.              Prior to the call to ClParse, a call MUST be made to ClInit.
  1029.  
  1030.              The procedure prepares a list of records, each record con-
  1031.         taining the name and value of one command line switch. These
  1032.         records will require 536 bytes of heap space per switch.
  1033.  
  1034.              All switches (with the optional exception of the first) are
  1035.         preceded by one of the members of the set LeadIn.
  1036.  
  1037.              Switches may take values of type Real (actually, Extended),
  1038.         LongInt, or String. In each case, the switch value is separated
  1039.         from the switch name by one of the characters specified in the
  1040.         parameter ValDelim. Switches which do not take on any explicit
  1041.         value will be returned as type String, with a value length of
  1042.         zero.
  1043.  
  1044.  
  1045.  
  1046.                                   ShCmdLin  2-4
  1047.  
  1048.  
  1049.  
  1050.              Assuming StrOnly = FALSE in the call, switches whose VALUE
  1051.         is intended to be of type String, but with a FORM qualifying as a
  1052.         numeric, must be enclosed in either single or double quotation
  1053.         marks. Otherwise, the value will be returned as a Real or
  1054.         LongInt, as determined by its specific syntax.
  1055.  
  1056.              Additionally, any blanks included in String values will be
  1057.         packed out unless the value is included in quotation marks.
  1058.         Further, if single quote marks are to be included as part of a
  1059.         string value, then double quotes must be used to define the
  1060.         value; and vice versa.
  1061.  
  1062.              Finally, blanks may be freely entered in the command tail to
  1063.         improve readability (except as noted above).
  1064.  
  1065.         Error Returns:
  1066.              The error parameter returns one of three values:
  1067.                   0 --> No error encountered.
  1068.                   1 --> Unbalanced single quotes encountered.
  1069.                   2 --> Unbalanced double quotes encountered.
  1070.                   3 --> Insufficient heap space to store the switch list.
  1071.  
  1072.              Assuming the error return is 0, the list of switches has
  1073.         been successfully prepared and is available for retrieval using
  1074.         GetSwitch or PopSwitch.
  1075.  
  1076.              If GetSwitch has been used to retrieve the switch values,
  1077.         ClClose should be called to release the heap space associated
  1078.         with the list of switches. This is not necessary if PopSwitch has
  1079.         been used for retrieval (but it won't hurt anything, either).
  1080.  
  1081.         Examples:
  1082.              See the files TESTCL.PAS and CLTEST.BAT
  1083.  
  1084.         See also:
  1085.              ClInit    ClClose   GetSwitch      PopSwitch
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.                                   ShCmdLin  2-5
  1105.  
  1106.  
  1107.  
  1108.         ____________________________
  1109.         GETSWITCH
  1110.  
  1111.         Declaration:
  1112.              function GetSwitch(var Y : SwRec) : boolean;
  1113.  
  1114.         Purpose:
  1115.              Retrieves the next switch record in the list of switch
  1116.         records prepared by ClParse. Returns FALSE if no more.
  1117.  
  1118.         Comments:
  1119.              The list of switches can, if desired, be treated as a ring
  1120.         (thus enabling switches to be read more than once). If GetSwitch
  1121.         is called again after returning a function value of FALSE, read-
  1122.         ing will recommence at the top of the list.
  1123.  
  1124.              Use of GetSwitch and PopSwitch should not be combined. If
  1125.         they are both used on the same pass through the command tail,
  1126.         orphan blocks (blocks which have no associated pointer, and thus
  1127.         cannot be accessed or retrieved) will result on the heap.
  1128.  
  1129.         Examples:
  1130.              See the files TESTCL.PAS and CLTEST.BAT
  1131.  
  1132.         See also:
  1133.              PopSwitch
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.                                   ShCmdLin  2-6
  1163.  
  1164.  
  1165.  
  1166.         ____________________________
  1167.         POPSWITCH
  1168.  
  1169.         Declaration:
  1170.              function PopSwitch(var Y : SwRec) : boolean;
  1171.  
  1172.         Purpose:
  1173.              Retrieves the next switch record in the list of switch
  1174.         records prepared by ClParse, and frees its heap space. Returns
  1175.         FALSE if no more.
  1176.  
  1177.         Comments:
  1178.              Since PopSwitch frees the heap space associated with each
  1179.         switch after it has been returned to the caller, it is not
  1180.         necessary to call ClClose after reaching the end of the switch
  1181.         list. For the same reason, however, the switch list cannot be
  1182.         treated as a ring (that is, the switch list cannot be reread
  1183.         after the end has been reached).
  1184.  
  1185.              Use of GetSwitch and PopSwitch should not be combined. If
  1186.         they are both used on the same pass through the command tail,
  1187.         orphan blocks (blocks which have no associated pointer, and thus
  1188.         cannot be accessed or retrieved) will result on the heap.
  1189.  
  1190.         Examples:
  1191.              See the files TESTCL.PAS and CLTEST.BAT
  1192.  
  1193.         See also:
  1194.              GetSwitch
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.                                   ShCmdLin  2-7
  1221.  
  1222.  
  1223.  
  1224.         ____________________________
  1225.         READSWCH
  1226.  
  1227.         Declaration:
  1228.              function ReadSwCh : char;
  1229.  
  1230.         Purpose:
  1231.              Returns the current switch lead-in character.
  1232.  
  1233.         Comments:
  1234.              DOS normally recognizes the character '/' as the switch
  1235.         lead-in. DOS also permits this character to be changed. In par-
  1236.         ticular, some installations whose personnel are more comfortable
  1237.         in a UNIX-like environment have changed the switch lead-in to
  1238.         '-'. The ReadSwCh function permits the programmer to assure that
  1239.         the character which DOS recognizes will be included in the set of
  1240.         permissible lead-in characters which the parser will also
  1241.         recognize.
  1242.  
  1243.         Examples:
  1244.              See the files TESTCL.PAS and CLTEST.BAT
  1245.  
  1246.         See also:
  1247.              SetSwCh
  1248.  
  1249.  
  1250.         ____________________________
  1251.         SETSWCH
  1252.  
  1253.         Declaration:
  1254.              procedure SetSwCh(C : char);
  1255.  
  1256.         Purpose:
  1257.              Sets the switch lead-in character to C.
  1258.  
  1259.         Comments:
  1260.              THIS PROCEDURE MODIFIES THE CURRENTLY RUNNING COPY OF DOS.
  1261.         Therefore it should only be used in exceptional circumstances,
  1262.         and with great caution. Otherwise the users could be in for quite
  1263.         a surprise! It is included here primarily for completeness.
  1264.  
  1265.         Examples:
  1266.                                   SetSwCh('+');
  1267.  
  1268.         will change the switch lead-in to '+'.
  1269.  
  1270.         See also:
  1271.              ReadSwCh
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.                                   ShCmdLin  2-8
  1279.                                                          03/25/92 01:54pm
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.                                      ShCmplx
  1287.  
  1288.                             A Complex Arithmetic Unit
  1289.  
  1290.  
  1291.         INTRODUCTION
  1292.              ShCmplx is a complex arithmetic unit for Turbo Pascal,
  1293.         version 5 or higher. It provides for the basic binary arithmetic
  1294.         functions (addition, subtraction, multiplication, division), plus
  1295.         the raising of a complex number to a real power. Conversion func-
  1296.         tions are provided to convert between a complex number repre-
  1297.         sented in Cartesian form and one represented in polar form.
  1298.         Finally, provision is made to convert a complex number in
  1299.         Cartesian form to a string; or a complex in polar form to a
  1300.         string expressing the angle either in degrees or in radians.
  1301.  
  1302.              All of the described functionality is available as a suite
  1303.         of Pascal functions. All except the string conversion routines
  1304.         are also available as Pascal procedures.
  1305.  
  1306.              However, recall that a complex number C is represented by
  1307.         two real numbers, say (R1, R2), where C = (R1 + i*R2) and i is
  1308.         the square root of -1. Thus, the representation is inherently a
  1309.         record structure. And Pascal functions can only return simple
  1310.         data types - no structured types.
  1311.  
  1312.              ShCmplx avoids this problem by storing all of its data on
  1313.         the heap. When a variable is declared to be of type Complex, this
  1314.         declaration establishes only a pointer in the data segment; the
  1315.         record structure itself is established on the heap.
  1316.  
  1317.              What this means in practice is that type complex, in this
  1318.         package, is not defined as
  1319.  
  1320.                   type
  1321.                     Complex = record
  1322.                                 Re,
  1323.                                 Im : ComplexElement;
  1324.                                 end;
  1325.  
  1326.         but, rather, as
  1327.  
  1328.                   type
  1329.                     ComplexBaseType = record
  1330.                                         Re,
  1331.                                         Im  : ComplexElement;
  1332.                                         end;
  1333.                     Complex         = ^ComplexBaseType;
  1334.  
  1335.  
  1336.  
  1337.                                    ShCmplx  3-1
  1338.  
  1339.  
  1340.  
  1341.              Thus, if we had an expression which we wished to evaluate -
  1342.         for example:
  1343.  
  1344.                                 A = A + B + C + D
  1345.  
  1346.         this is able to be evaluated (where CAddF is the function name
  1347.         for complex addition) as:
  1348.  
  1349.                      A^ := CAddF(CAddF(A, B), CAddF(C, D))^;
  1350.  
  1351.         which is the equivalent of (with the pointers de-referenced)
  1352.  
  1353.                             A := ((A + B) + (C + D));
  1354.         or
  1355.                      A^ := CAddF(A, CAddF(B, CAddF(C, D)))^;
  1356.  
  1357.         which is the equivalent of (again, with the pointers de-
  1358.         referenced)
  1359.  
  1360.                             A := (A + (B + (C + D)));
  1361.  
  1362.         and the result of this calculation can be displayed using either
  1363.  
  1364.                             WriteLn(Cmp2Str(A, 8, 4));
  1365.         or
  1366.              WriteLn(Cmp2Str(CAddF(CAddF(A, B), CAddF(C, D)), 8, 4));
  1367.  
  1368.         where the "8, 4" in each case carry the same significance as the
  1369.         parameters used in printing real quantities; specifically, the
  1370.         total field width and number of places to the right of the
  1371.         decimal point (in this case, for each numeric component).
  1372.  
  1373.              Note that
  1374.  
  1375.                                 A := CAddF(B, C);
  1376.  
  1377.         is normally not what you would want. This would assign the
  1378.         returned pointer value to the pointer variable 'A', rather than
  1379.         assigning the complex value pointed to by the returned pointer to
  1380.         the element pointed to by 'A', which you would get by writing
  1381.  
  1382.                                A^ := CAddF(B, C)^;
  1383.  
  1384.              This type of error is, unfortunately, not detectable by the
  1385.         Pascal compiler, the run-time system, or at the level of any ap-
  1386.         plication software. So you need to be careful that you don't do
  1387.         it to yourself.
  1388.  
  1389.              A test program (TESTCMPX.PAS) is included with the distribu-
  1390.         tion set. Study it for ideas and specifics of how to use the
  1391.         various functions.
  1392.  
  1393.  
  1394.  
  1395.                                    ShCmplx  3-2
  1396.  
  1397.  
  1398.  
  1399.         INTERFACED ELEMENTS
  1400.  
  1401.         Types
  1402.         =====
  1403.              ComplexElement  = extended;
  1404.              ComplexBaseType = record
  1405.                                  Re,
  1406.                                  Im  : ComplexElement;
  1407.                                  end;
  1408.              Complex         = ^ComplexBaseType;
  1409.  
  1410.  
  1411.         Routines
  1412.         ========
  1413.  
  1414.         ____________________________
  1415.         C2P
  1416.  
  1417.         Declarations:
  1418.              procedure C2P(A : Complex; var Result : Complex);
  1419.              function C2PF(A : Complex) : Complex;
  1420.  
  1421.         Purpose:
  1422.              Transforms a complex in Cartesian form into polar form.
  1423.  
  1424.         Examples:
  1425.              CpPwrR(C2PF(MyCmpx), 3.0, MyCmpxCubedPolar);
  1426.  
  1427.         Comments:
  1428.              The magnitude will be stored in Result^.Re and the angle
  1429.         (expressed in radians) in Result^.Im
  1430.  
  1431.         See Also:
  1432.              P2C
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.                                    ShCmplx  3-3
  1454.  
  1455.  
  1456.  
  1457.         ____________________________
  1458.         CABS
  1459.  
  1460.         Declarations:
  1461.              procedure CAbs(A  : Complex; var Result : ComplexElement);
  1462.              function CAbsF(A  : Complex)  : ComplexElement;
  1463.  
  1464.         Purpose:
  1465.              Returns the absolute value of a complex number.
  1466.  
  1467.         Examples:
  1468.              ∙∙∙
  1469.              MyCmpx^.Re := 3.0;
  1470.              MyCmpx^.Im := 4.0;
  1471.              ∙∙∙
  1472.              WriteLn(CAbs(MyCmpx):4:1);    {will display 5.0}
  1473.  
  1474.         Comments:
  1475.              Recall that the absolute value of a complex number Re + iIm
  1476.         is sqrt((Re * Re) + (Im * Im)).
  1477.  
  1478.         See Also:
  1479.  
  1480.  
  1481.         ____________________________
  1482.         CADD
  1483.  
  1484.         Declarations:
  1485.              procedure CAdd(A, B : Complex; var Result : Complex);
  1486.              function CAddF(A, B : Complex) : Complex;
  1487.  
  1488.         Purpose:
  1489.              Returns the sum of two complex numbers A + B.
  1490.  
  1491.         Examples:
  1492.              See the file TESTCMPX.PAS
  1493.  
  1494.         Comments:
  1495.  
  1496.         See Also:
  1497.              CSub      CMul      CDiv
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.                                    ShCmplx  3-4
  1512.  
  1513.  
  1514.  
  1515.         ____________________________
  1516.         CCONJ
  1517.  
  1518.         Declarations:
  1519.              procedure CConj(A : Complex; var Result : Complex);
  1520.              function CConjF(A : Complex) : Complex;
  1521.  
  1522.         Purpose:
  1523.              Returns the complex conjugate of a complex number.
  1524.  
  1525.         Examples:
  1526.              See the file TESTCMPX.PAS
  1527.  
  1528.         Comments:
  1529.              Recall that if a complex number A = R + Ii, then the complex
  1530.         conjugate of A is R - Ii.
  1531.  
  1532.         See Also:
  1533.  
  1534.  
  1535.         ____________________________
  1536.         CDIV
  1537.  
  1538.         Declarations:
  1539.              procedure CDiv(A, B : Complex; var Result : Complex);
  1540.              function CDivF(A, B : Complex) : Complex;
  1541.  
  1542.         Purpose:
  1543.              Returns the quotient of two complex numbers A / B.
  1544.  
  1545.         Examples:
  1546.              See the file TESTCMPX.PAS
  1547.  
  1548.         Comments:
  1549.              CAbsF(B) must be > 0.0. If CAbsF(B) <= 0.0, CmplxError will
  1550.         return -1.
  1551.  
  1552.         See Also:
  1553.              CAdd      CMul      CSub
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.                                    ShCmplx  3-5
  1570.  
  1571.  
  1572.  
  1573.         ____________________________
  1574.         CMP2STR
  1575.  
  1576.         Declarations:
  1577.              function Cmp2Str(A : Complex; Width, Places : byte) :
  1578.                                                                string;
  1579.  
  1580.         Purpose:
  1581.              Converts a complex value to a string of the form
  1582.                                    (Re + Im i)
  1583.  
  1584.         Examples:
  1585.              See the file TESTCMPX.PAS
  1586.  
  1587.         Comments:
  1588.              The Width and Places arguments have the same significance
  1589.         that they do in the system procedure STR, and are applied
  1590.         individually to both the REAL and IMAGINARY parts.
  1591.  
  1592.         See Also:
  1593.              CmpP2Str       CmpP2StrD
  1594.  
  1595.  
  1596.         ____________________________
  1597.         CMPLXERROR
  1598.  
  1599.         Declarations:
  1600.              function CmplxError  : integer;
  1601.  
  1602.         Purpose:
  1603.              Returns execution error conditions for the package.
  1604.  
  1605.         Examples:
  1606.              See the file TESTCMPX.PAS
  1607.  
  1608.         Comments:
  1609.              Return = 0     OK
  1610.                       -1    Attempt to divide by zero (CDiv)
  1611.                       -2    Magnitude of complex is zero (CpPwrR)
  1612.  
  1613.         See Also:
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.                                    ShCmplx  3-6
  1628.  
  1629.  
  1630.  
  1631.         ____________________________
  1632.         CMPP2STR
  1633.  
  1634.         Declarations:
  1635.              function CmpP2Str(A : Complex; Width, Places : byte) :
  1636.                                                                string;
  1637.  
  1638.         Purpose:
  1639.              Converts a complex in polar form to a string with the angle
  1640.         expressed in radians.
  1641.  
  1642.         Examples:
  1643.              See the file TESTCMPX.PAS
  1644.  
  1645.         Comments:
  1646.              The Width and Places arguments have the same significance
  1647.         that they do in the system procedure STR, and are applied
  1648.         individually to both the MAGNITUDE and ANGLE parts.
  1649.  
  1650.         See Also:
  1651.              Cmp2Str        CmpP2StrD
  1652.  
  1653.  
  1654.         ____________________________
  1655.         CMPP2STRD
  1656.  
  1657.         Declarations:
  1658.              function CmpP2StrD(A : Complex; Width, Places : byte) :
  1659.                                                                string;
  1660.  
  1661.         Purpose:
  1662.              Converts a complex in polar form to a string with the angle
  1663.         in degrees.
  1664.  
  1665.         Examples:
  1666.              See the file TESTCMPX.PAS
  1667.  
  1668.         Comments:
  1669.              The Width and Places arguments have the same significance
  1670.         that they do in the system procedure STR, and are applied
  1671.         individually to both the MAGNITUDE and ANGLE parts.
  1672.  
  1673.         See Also:
  1674.              Cmp2Str        CmpP2Str
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.                                    ShCmplx  3-7
  1686.  
  1687.  
  1688.  
  1689.         ____________________________
  1690.         CMUL
  1691.  
  1692.         Declarations:
  1693.              procedure CMul(A, B : Complex; var Result : Complex);
  1694.              function CMulF(A, B : Complex) : Complex;
  1695.  
  1696.         Purpose:
  1697.              Returns the product of two complex numbers A * B.
  1698.  
  1699.         Example:
  1700.              See the file TESTCMPX.PAS
  1701.  
  1702.         Comments:
  1703.  
  1704.         See Also:
  1705.              CAdd      CDiv      CSub      RxC
  1706.  
  1707.  
  1708.         ____________________________
  1709.         CPPWRR
  1710.  
  1711.         Declarations:
  1712.              procedure CpPwrR(A : Complex; R : ComplexElement;
  1713.                                                 var Result : Complex);
  1714.              function CpPwrRF(A : Complex; R : ComplexElement) : Complex;
  1715.  
  1716.         Purpose:
  1717.              Raises a complex (in polar form) to a real power.
  1718.  
  1719.         Examples:
  1720.              See the file TESTCMPX.PAS
  1721.  
  1722.         Comments:
  1723.              If A^.Re = 0, CmplxError will return -2, and
  1724.                            Result will be 0 + 0i
  1725.                            n.b. A^.Re contains the magnitude.
  1726.  
  1727.         See Also:
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.                                    ShCmplx  3-8
  1744.  
  1745.  
  1746.  
  1747.         ____________________________
  1748.         CSUB
  1749.  
  1750.         Declarations:
  1751.              procedure CSub(A, B : Complex; var Result : Complex);
  1752.              function CSubF(A, B : Complex) : Complex;
  1753.  
  1754.         Purpose:
  1755.              Returns the difference between two complex numbers A - B.
  1756.  
  1757.         Examples:
  1758.              See the file TESTCMPX.PAS
  1759.  
  1760.         Comments:
  1761.  
  1762.         See Also:
  1763.              CAdd      CDiv      CMul
  1764.  
  1765.  
  1766.         ____________________________
  1767.         P2C
  1768.  
  1769.         Declarations:
  1770.              procedure P2C(A : Complex; var Result : Complex);
  1771.              function P2CF(A : Complex) : Complex;
  1772.  
  1773.         Purpose:
  1774.              Transforms a complex in polar form into Cartesian form. The
  1775.         magnitude is stored in A^.Re and the angle (expressed in radians)
  1776.         in A^.Im.
  1777.  
  1778.         Examples:
  1779.              See the file TESTCMPX.PAS
  1780.  
  1781.         Comments:
  1782.  
  1783.         See Also:
  1784.              C2P
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794.  
  1795.  
  1796.  
  1797.  
  1798.  
  1799.  
  1800.  
  1801.                                    ShCmplx  3-9
  1802.  
  1803.  
  1804.  
  1805.         ____________________________
  1806.         RXC
  1807.  
  1808.         Declarations:
  1809.              procedure RxC(A : ComplexElement; B : Complex;
  1810.                                                 var Result : Complex);
  1811.              function RxCF(A : ComplexElement; B : Complex) : Complex;
  1812.  
  1813.         Purpose:
  1814.              Returns the complex product of a real and a complex.
  1815.  
  1816.         Examples:
  1817.              See the file TESTCMPX.PAS
  1818.  
  1819.         Comments:
  1820.              This is simply a special case of CMul, in which the
  1821.         imaginary part of one of the factors is zero. It occurrs with
  1822.         sufficient frequency, however, to warrent separate treatment.
  1823.  
  1824.         See Also:
  1825.              CMul
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856.  
  1857.  
  1858.  
  1859.                                   ShCmplx  3-10
  1860.                                                          03/25/92 01:54pm
  1861.  
  1862.  
  1863.  
  1864.  
  1865.  
  1866.  
  1867.                                     ShCrcChk
  1868.  
  1869.                           A File CRC16 Calculation Unit
  1870.  
  1871.  
  1872.         INTRODUCTION
  1873.              ShCrcChk interfaces two procedures, both of which calculates
  1874.         the CRC16 of a file whose name is provided as a string parameter.
  1875.  
  1876.              When the DOS COPY command is used, no true read-after-write
  1877.         verification is performed. The only way to assure that the re-
  1878.         cording was correct is to read the file after writing, and com-
  1879.         pare the output file, byte for byte, with the input. For very
  1880.         long files this can result in unacceptable delays.
  1881.  
  1882.              A reasonable compromise between speed and reliability is to
  1883.         calculate the cyclic redundancy check (CRC) word of the input
  1884.         file as it is being copied, and then on completion of the copying
  1885.         operation, read back the output file and calculate its CRC. If
  1886.         the two compare, the probability that the two files differ is
  1887.         extremely small, especially if the two files are of the same
  1888.         size.
  1889.  
  1890.  
  1891.         OVERVIEW
  1892.              For those unfamiliar with CRCs, suffice to say that they are
  1893.         very powerful generalizations of the familiar 'parity check'
  1894.         schemes, such as those which have been used at least since the
  1895.         early days of digital magnetic tape recording.
  1896.  
  1897.              CRCs are calculated by performing iterative calculations,
  1898.         byte by byte, on a data block, using specific algebraic poly-
  1899.         nomials to determine the manner in which individual bits of each
  1900.         byte are to be used in the calculation. The determination of
  1901.         suitable polynomials is the subject of an extensive body of
  1902.         literature.
  1903.  
  1904.              The CCITT (for those who enjoy living life the hard way,
  1905.         CCITT is the designation for the International Consultative
  1906.         Committee for Telephone and Telegraph, a branch of the United
  1907.         Nations) has recommended the use of a specific generator poly-
  1908.         nomial for use in calculating the CRC for data blocks in asyn-
  1909.         chronous communications. This polynomial is
  1910.  
  1911.                              (X^16 + X^12 + X^5 + 1).
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.                                   ShCrcChk  4-1
  1919.  
  1920.  
  1921.  
  1922.              While its recommended use primarily deals with block trans-
  1923.         mission of data over asynchronous links (as in the X/Y/ZMODEM
  1924.         protocols), it has come into widespread use also as a generator
  1925.         polynomial for file-level CRC. This is therefore the generator
  1926.         polynomial which has been used for ShCrcChk.
  1927.  
  1928.              Those sufficiently interested and/or masochistic as to want
  1929.         to find additional information regarding the theory of CRC are
  1930.         referred to:
  1931.  
  1932.              1. SOBOLEWSKI, J.S., "Cyclic Redundancy Check", in Ralston,
  1933.         A. (ed.), Encyclopedia of Computer Science and Engineering (2nd
  1934.         Ed.), Van Nostrand Reinhold Co., 1983, p.434ff
  1935.  
  1936.              2. PLESS, V., "Introduction to the Theory of Error-
  1937.         Correcting Codes", John Wiley and Sons, 1982, p. 59ff
  1938.  
  1939.              Both of these references include bibliography for additional
  1940.         study.
  1941.  
  1942.  
  1943.         INTERFACED ELEMENTS
  1944.  
  1945.         Routines
  1946.         ========
  1947.         ____________________________
  1948.         CRCCALC
  1949.  
  1950.         Declaration:
  1951.              function CrcCalc(FileName : String) : word;
  1952.  
  1953.         Purpose:
  1954.               To calculate the CRC16 of a named file, assumed to exist.
  1955.  
  1956.         Example:
  1957.               if CrcCalc(MyFile) <> CrcShouldBe then begin
  1958.                 (*Take remedial action*)
  1959.                 end;
  1960.  
  1961.         Comments:
  1962.               MyFile is a file of any type, and may have any attributes
  1963.         including Hidden, ReadOnly, etc. A run time error will result,
  1964.         however, if the file does not exist.
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.                                   ShCrcChk  4-2
  1977.  
  1978.  
  1979.  
  1980.         ____________________________
  1981.         CRCCOPY
  1982.  
  1983.         Declaration:
  1984.              function CrcCopy(InFileName, OutFileName : String) : word;
  1985.  
  1986.         Purpose:
  1987.               Calculates the CRC16 value for file=InFileName, while
  1988.         copying it to file=OutFileName.
  1989.  
  1990.         Example:
  1991.               CrcShouldBe := CrcCopy(FileFromYou, MyFile);
  1992.               if CrcCopy(MyFile, '') <> CrcShouldBe then begin
  1993.                 (*Take remedial action*)
  1994.                 end;
  1995.  
  1996.         Comments:
  1997.               The output file name is optional. If OutFileName is speci-
  1998.         fied, InFileName is copied to OutFileName. If OutFileName is an
  1999.         empty string, CrcCopy behaves exactly like CrcCalc. In either
  2000.         case, the CRC16 value of InFileName is returned.
  2001.  
  2002.               Using CrcCopy simply to calculate the CRC16 of the input
  2003.         file will be marginally slower than using CrcCalc. In cases in
  2004.         which both functionalities are required, however, using CrcCopy
  2005.         exclusively will result in a somewhat smaller code segment.
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.                                   ShCrcChk  4-3
  2035.                                                          03/25/92 01:54pm
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053.  
  2054.  
  2055.  
  2056.  
  2057.                        This page has been deliberately left
  2058.                          blank, except for this message.
  2059.  
  2060.  
  2061.  
  2062.  
  2063.  
  2064.  
  2065.  
  2066.  
  2067.  
  2068.  
  2069.  
  2070.  
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.  
  2078.  
  2079.  
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.                                   ShCrcChk  4-4
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.                                      ShDatPk
  2101.  
  2102.                              A Date Manipulation Unit
  2103.  
  2104.         INTRODUCTION
  2105.              ShDatPk is a set of routines intended to simplify the
  2106.         accurate manipulation of dates. These routines are based on
  2107.         Algorithm #398 and associated comments, from the Collected
  2108.         Algorithms of the ACM.
  2109.  
  2110.              Originally distributed as DATEPACK for TURBO/PASCAL ver. 3
  2111.         (and compatible with ver. 4), the routines relied heavily on Real
  2112.         arithmetic. Re-written here for ver. 4 and above, all Real arith-
  2113.         metic has been replaced by LongInt. This results in a speed-up of
  2114.         nearly 60%, over the original DATEPACK routines compiled with
  2115.         real arithmetic but without a math coprocessor.
  2116.  
  2117.              Before proceeding, several definitions are necessary to
  2118.         provide the framework for understanding the various conversions
  2119.         possible through the use of the ShDatPk routines.
  2120.  
  2121.  
  2122.         GREGORIAN DATE  is the date system commonly used in modern
  2123.                        western nations. Established by Papal bull in
  2124.                        March 1582, it adjusted the calendar in use up to
  2125.                        that time in order to restore the vernal equinox
  2126.                        to March 21. This was accomplished by suppressing
  2127.                        the dates from the 5th through the 14th
  2128.                        (inclusive) of October, 1582. While the Gregorian
  2129.                        calendar was accepted quickly throughout most of
  2130.                        Europe, it was not adopted in England and the
  2131.                        Colonies until 1752. When YEAR, MONTH, and/or DAY
  2132.                        are passed or returned as parameters in the
  2133.                        ShDatPk  routines, the Gregorian system is
  2134.                        assumed.
  2135.  
  2136.         JULIAN DAY-NUMBER
  2137.         JULIAN DAY      is the representation of a given date as its
  2138.                        serial index, beginning on January 1, 4713 B.C.
  2139.                        The date chosen as the basis has astronomical
  2140.                        significance, and is widely recognized in the
  2141.                        scientific community. Proposed by the astronomer
  2142.                        Joseph Scaliger, it is named in memory of his
  2143.                        father and not, as often assumed, for Julius
  2144.                        Caesar. When used as a parameter by any of the
  2145.                        ShDatPk routines, it will be passed as a LongInt
  2146.                        representation of a 7 digit integer.
  2147.  
  2148.  
  2149.  
  2150.  
  2151.                                    ShDatPk  5-1
  2152.  
  2153.  
  2154.  
  2155.         JULIAN DATE     is the representation of a given date as its
  2156.                        serial index, taking January 1st  of the given
  2157.                        year as the base (=1). When used as a parameter by
  2158.                        any of the ShDatPk routines, both the serial index
  2159.                        and the year will be represented as simple
  2160.                        integers. (By the way, this one was named for
  2161.                        Julius Caesar).
  2162.  
  2163.         SMITHSONIAN DATE
  2164.                         is the representation of a given date as its
  2165.                        serial index, with November 18, 1858 as the base
  2166.                        (=1). While routines are not included for
  2167.                        converting from or to the Smithsonian date, it is
  2168.                        readily calculated from the Julian Day as
  2169.  
  2170.                                  Smithsonian = Julian - 2400001
  2171.  
  2172.  
  2173.         INTERFACED ELEMENTS
  2174.  
  2175.         Types
  2176.         =====
  2177.              GregType  = record
  2178.                            Year  : LongInt;
  2179.                            Month,
  2180.                            Day   : byte;
  2181.                            end;
  2182.              Variables of this type contain a complete Gregorian date,
  2183.         and are passed to many of the routines in this unit.
  2184.  
  2185.              TimeType  = record
  2186.                            H,
  2187.                            M,
  2188.                            S   : byte;
  2189.                            end;
  2190.              Variables of this type contain a complete time record, and
  2191.         are passed to many of the routines in this unit.
  2192.  
  2193.  
  2194.         Constants
  2195.         =========
  2196.              DayStr  : array[0..6] of string[9] =
  2197.                            ('Sunday'   , 'Monday'   , 'Tuesday'  ,
  2198.                             'Wednesday', 'Thursday' , 'Friday'   ,
  2199.                             'Saturday' );
  2200.  
  2201.              MonthStr: array[1..12] of string[9] =
  2202.                            ('January'  , 'February' , 'March',
  2203.                             'April'    , 'May'      , 'June',
  2204.                             'July'     , 'August'   , 'September',
  2205.                             'October'  , 'November' , 'December');
  2206.  
  2207.  
  2208.  
  2209.                                    ShDatPk  5-2
  2210.  
  2211.  
  2212.  
  2213.         Routines
  2214.         ========
  2215.         ____________________________
  2216.         DOW
  2217.  
  2218.         Declaration:
  2219.              function DoW(Greg : GregType) : byte;
  2220.  
  2221.         Purpose:
  2222.              To compute the day of the week (Sunday = 0; Saturday = 6)
  2223.         from the Gregorian date.
  2224.  
  2225.         Examples:
  2226.              See TESTDATE.PAS
  2227.  
  2228.         Comments:
  2229.  
  2230.         See also:
  2231.  
  2232.  
  2233.         ____________________________
  2234.         GREG2ANSI
  2235.  
  2236.         Declaration:
  2237.              function Greg2ANSI(G : GregType) : string;
  2238.  
  2239.         Purpose:
  2240.              Given a Gregorian date, return the date as an ANSI date
  2241.         string (YYYYMMDD).
  2242.  
  2243.         Examples:
  2244.              See TESTDATE.PAS
  2245.  
  2246.         Comments:
  2247.              Note that the ANSI date format is both sortable and
  2248.         readable.
  2249.  
  2250.         See also:
  2251.              JDN2ANSI
  2252.  
  2253.  
  2254.  
  2255.  
  2256.  
  2257.  
  2258.  
  2259.  
  2260.  
  2261.  
  2262.  
  2263.  
  2264.  
  2265.  
  2266.  
  2267.                                    ShDatPk  5-3
  2268.  
  2269.  
  2270.  
  2271.         ____________________________
  2272.         GREG2JDATE
  2273.  
  2274.         Declaration:
  2275.              function Greg2JDate(Greg : GregType) : integer;
  2276.  
  2277.         Purpose:
  2278.              To compute the Julian date from the Gregorian date.
  2279.  
  2280.         Examples:
  2281.              See TESTDATE.PAS
  2282.  
  2283.         Comments:
  2284.              Do not confuse the Julian date with the Julian Day-Number.
  2285.         The Julian date, most commonly used in business applications, is
  2286.         the serial index of a date WITHIN A GIVEN YEAR. The Julian Day-
  2287.         Number is the serial index of a date from January 1, 4713 B.C.
  2288.  
  2289.         See also:
  2290.              JDate2Greg
  2291.  
  2292.  
  2293.         ____________________________
  2294.         GREG2JDN
  2295.  
  2296.         Declaration:
  2297.              function Greg2JDN(Greg : GregType) : LongInt;
  2298.  
  2299.         Purpose:
  2300.              To convert a Gregorian date into a Julian Day-Number.
  2301.  
  2302.         Examples:
  2303.              See TESTDATE.PAS
  2304.  
  2305.         Comments:
  2306.              The Julian Day-Number (JDN) is the basic form for date
  2307.         manipulation within this unit. Thus this function performs the
  2308.         primary conversion between dates in the customary form and
  2309.         equivalent dates suitable for manipulation by ShDatPk.
  2310.  
  2311.         See also:
  2312.              JDN2Greg
  2313.  
  2314.  
  2315.  
  2316.  
  2317.  
  2318.  
  2319.  
  2320.  
  2321.  
  2322.  
  2323.  
  2324.  
  2325.                                    ShDatPk  5-4
  2326.  
  2327.  
  2328.  
  2329.         ____________________________
  2330.         JDATE2GREG
  2331.  
  2332.         Declaration:
  2333.              procedure JDate2Greg(JDate, Year : Integer;
  2334.                                                     var Greg : GregType);
  2335.  
  2336.         Purpose:
  2337.              To compute the Gregorian date from the Julian date.
  2338.  
  2339.         Examples:
  2340.              See TESTDATE.PAS
  2341.  
  2342.         Comments:
  2343.              Do not confuse the Julian date with the Julian Day-Number.
  2344.         The Julian date, most commonly used in business applications, is
  2345.         the serial index of a date WITHIN A GIVEN YEAR. The Julian Day-
  2346.         Number is the serial index of a date from January 1, 4713 B.C.
  2347.  
  2348.         See also:
  2349.              Greg2JDate
  2350.  
  2351.  
  2352.         ____________________________
  2353.         JDN2ANSI
  2354.  
  2355.         Declaration:
  2356.              function JDN2ANSI(JDN : LongInt) : string;
  2357.  
  2358.         Purpose:
  2359.              Given a Julian Day-Number, return the JDN as an ANSI date
  2360.         string (YYYYMMDD).
  2361.  
  2362.         Examples:
  2363.              See TESTDATE.PAS
  2364.  
  2365.         Comments:
  2366.              Note that the ANSI date format is both sortable and
  2367.         readable.
  2368.  
  2369.         See also:
  2370.              Greg2ANSI
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382.  
  2383.                                    ShDatPk  5-5
  2384.  
  2385.  
  2386.  
  2387.         ____________________________
  2388.         JDN2GREG
  2389.  
  2390.         Declaration:
  2391.              procedure JDN2Greg(JDN : LongInt; var Greg : GregType);
  2392.  
  2393.         Purpose:
  2394.              To compute the Gregorian date from the Julian Day-Number.
  2395.  
  2396.         Examples:
  2397.              See TESTDATE.PAS
  2398.  
  2399.         Comments:
  2400.              The Julian Day-Number (JDN) is the basic form for date
  2401.         manipulation within this unit. Thus this function performs the
  2402.         primary conversion between dates in ShDatPk internal form and
  2403.         equivalent dates in the customary form.
  2404.  
  2405.         See also:
  2406.              Greg2JDN
  2407.  
  2408.  
  2409.         ____________________________
  2410.         GREG2STR
  2411.  
  2412.         Declaration:
  2413.              function Greg2Str(G : GregType; Delim : string) : string;
  2414.  
  2415.         Purpose:
  2416.              Returns a Gregorian date record as a string of the form
  2417.         MMdDDdYYYY, where the separator, "d", is Delim[1].
  2418.  
  2419.         Examples:
  2420.              See TESTDATE.PAS
  2421.  
  2422.         Comments:
  2423.  
  2424.         See also:
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440.  
  2441.                                    ShDatPk  5-6
  2442.  
  2443.  
  2444.  
  2445.         ____________________________
  2446.         JDN2STR
  2447.  
  2448.         Declaration:
  2449.              function JDN2Str(JDN : LongInt; Delim : string) : string;
  2450.  
  2451.         Purpose:
  2452.              Returns a Julian Day-Number as a string of the form
  2453.         MMdDDdYYYY, where the separator, "d", is Delim[1].
  2454.  
  2455.         Examples:
  2456.              See TESTDATE.PAS
  2457.  
  2458.         Comments:
  2459.  
  2460.         See also:
  2461.  
  2462.  
  2463.         ____________________________
  2464.         NOW
  2465.  
  2466.         Declaration:
  2467.              function Now  : LongInt;
  2468.  
  2469.         Purpose:
  2470.              Returns the system time as Seconds-Since-Midnight.
  2471.  
  2472.         Examples:
  2473.              See TESTDATE.PAS
  2474.  
  2475.         Comments:
  2476.  
  2477.         See also:
  2478.  
  2479.  
  2480.         ____________________________
  2481.         NOW2TIME
  2482.  
  2483.         Declaration:
  2484.              procedure Now2Time(var T : TimeType);
  2485.  
  2486.         Purpose:
  2487.              Returns the system time as a Time record.
  2488.  
  2489.         Examples:
  2490.              See TESTDATE.PAS
  2491.  
  2492.         Comments:
  2493.  
  2494.         See also:
  2495.  
  2496.  
  2497.  
  2498.  
  2499.                                    ShDatPk  5-7
  2500.  
  2501.  
  2502.  
  2503.         ____________________________
  2504.         NOWSTR
  2505.  
  2506.         Declaration:
  2507.              function NowStr(Delim : string; T24 : boolean) : string;
  2508.  
  2509.         Purpose:
  2510.              Returns the system time as a string of the form:
  2511.  
  2512.              HHdMMdSSss     if Delim is non-empty and T24 (24 hour time)
  2513.                            is false. The delimiter used, "d", is
  2514.                            Delim[1]. The suffix, "ss", is "am" or "pm" as
  2515.                            appropriate.
  2516.              HHdMMdSS       if Delim is non-empty and T24 (24 hour time)
  2517.                            is true. The delimiter used, "d", is Delim[1].
  2518.                            The time will be expressed in 24-hour form.
  2519.              HHMMSSss       if Delim is empty and T24 (24 hour time) is
  2520.                            false. The suffix, "ss", is "am" or "pm" as
  2521.                            appropriate.
  2522.              HHMM           if Delim is empty and T24 (24 hour time) is
  2523.                            true. The time will be expressed in 24-hour
  2524.                            form.
  2525.  
  2526.         Examples:
  2527.              See TESTDATE.PAS
  2528.  
  2529.         Comments:
  2530.  
  2531.         See also:
  2532.  
  2533.  
  2534.         ____________________________
  2535.         SSM2TIME
  2536.  
  2537.         Declaration:
  2538.              procedure SSM2Time(SSM : LongInt; var T : TimeType);
  2539.  
  2540.         Purpose:
  2541.              Converts Seconds-Since-Midnight to a Time record.
  2542.  
  2543.         Examples:
  2544.              See TESTDATE.PAS
  2545.  
  2546.         Comments:
  2547.  
  2548.         See also:
  2549.  
  2550.  
  2551.  
  2552.  
  2553.  
  2554.  
  2555.  
  2556.  
  2557.                                    ShDatPk  5-8
  2558.  
  2559.  
  2560.  
  2561.         ____________________________
  2562.         SSM2TIMESTR
  2563.  
  2564.         Declaration:
  2565.              function SSM2TimeStr(SSM : LongInt; Delim : string;
  2566.                                                  T24 : boolean) : string;
  2567.  
  2568.         Purpose:
  2569.              Converts Seconds-Since-Midnight to a time string, of the
  2570.         form:
  2571.  
  2572.              HHdMMdSSss     if Delim is non-empty and T24 (24 hour time)
  2573.                            is false. The delimiter used, "d", is
  2574.                            Delim[1]. The suffix, "ss", is "am" or "pm" as
  2575.                            appropriate.
  2576.              HHdMMdSS       if Delim is non-empty and T24 (24 hour time)
  2577.                            is true. The delimiter used, "d", is Delim[1].
  2578.                            The time will be expressed in 24-hour form.
  2579.              HHMMSSss       if Delim is empty and T24 (24 hour time) is
  2580.                            false. The suffix, "ss", is "am" or "pm" as
  2581.                            appropriate.
  2582.              HHMM           if Delim is empty and T24 (24 hour time) is
  2583.                            true. The time will be expressed in 24-hour
  2584.                            form.
  2585.  
  2586.         Examples:
  2587.              See TESTDATE.PAS
  2588.  
  2589.         Comments:
  2590.  
  2591.         See also:
  2592.  
  2593.  
  2594.         ____________________________
  2595.         TIME2SSM
  2596.  
  2597.         Declaration
  2598.              function Time2SSM(T : TimeType) : LongInt;
  2599.  
  2600.         Purpose:
  2601.              Converts a Time record to Seconds-Since-Midnight.
  2602.  
  2603.         Examples:
  2604.              See TESTDATE.PAS
  2605.  
  2606.         Comments:
  2607.  
  2608.         See also:
  2609.  
  2610.  
  2611.  
  2612.  
  2613.  
  2614.  
  2615.                                    ShDatPk  5-9
  2616.  
  2617.  
  2618.  
  2619.         ____________________________
  2620.         TIME2TIMESTR
  2621.  
  2622.         Declaratin:
  2623.              function Time2TimeStr(T : TimeType; Delim : string;
  2624.                                                  T24 : boolean) : string;
  2625.  
  2626.         Purpose:
  2627.              Converts a time record to a time string of the form:
  2628.  
  2629.              HHdMMdSSss     if Delim is non-empty and T24 (24 hour time)
  2630.                            is false. The delimiter used, "d", is
  2631.                            Delim[1]. The suffix, "ss", is "am" or "pm" as
  2632.                            appropriate.
  2633.              HHdMMdSS       if Delim is non-empty and T24 (24 hour time)
  2634.                            is true. The delimiter used, "d", is Delim[1].
  2635.                            The time will be expressed in 24-hour form.
  2636.              HHMMSSss       if Delim is empty and T24 (24 hour time) is
  2637.                            false. The suffix, "ss", is "am" or "pm" as
  2638.                            appropriate.
  2639.              HHMM           if Delim is empty and T24 (24 hour time) is
  2640.                            true. The time will be expressed in 24-hour
  2641.                            form.
  2642.  
  2643.         Examples:
  2644.              See TESTDATE.PAS
  2645.  
  2646.         Comments:
  2647.  
  2648.         See also:
  2649.  
  2650.  
  2651.         ____________________________
  2652.         TODAY
  2653.  
  2654.         Declaration:
  2655.              function Today  : LongInt;
  2656.  
  2657.         Purpose:
  2658.              Returns the system date as a Julian Day-Number.
  2659.  
  2660.         Examples:
  2661.              See TESTDATE.PAS
  2662.  
  2663.         Comments:
  2664.  
  2665.         See also:
  2666.  
  2667.  
  2668.  
  2669.  
  2670.  
  2671.  
  2672.  
  2673.                                   ShDatPk  5-10
  2674.  
  2675.  
  2676.  
  2677.         ____________________________
  2678.         TODAY2ANSI
  2679.  
  2680.         Declaration:
  2681.              function Today2ANSI : string;
  2682.  
  2683.         Purpose:
  2684.              Returns the system date as an ANSI date string (YYYYMMDD).
  2685.  
  2686.         Examples:
  2687.              See TESTDATE.PAS
  2688.  
  2689.         Comments:
  2690.              Note that the ANSI date format is both sortable and
  2691.         readable.
  2692.  
  2693.         See also:
  2694.  
  2695.  
  2696.         ____________________________
  2697.         TODAY2GREG
  2698.  
  2699.         Declaration:
  2700.              procedure Today2Greg(var G : GregType);
  2701.  
  2702.         Purpose:
  2703.              Returns the system date as a Gregorian date record.
  2704.  
  2705.         Examples:
  2706.              See TESTDATE.PAS
  2707.  
  2708.         Comments:
  2709.  
  2710.         See also:
  2711.  
  2712.  
  2713.  
  2714.  
  2715.  
  2716.  
  2717.  
  2718.  
  2719.  
  2720.  
  2721.  
  2722.  
  2723.  
  2724.  
  2725.  
  2726.  
  2727.  
  2728.  
  2729.  
  2730.  
  2731.                                   ShDatPk  5-11
  2732.  
  2733.  
  2734.  
  2735.         ____________________________
  2736.         TODAYSTR
  2737.  
  2738.         Declaration:
  2739.              function TodayStr(Delim : string) : string;
  2740.  
  2741.         Purpose:
  2742.              Returns the system date as a string of the form MMdDDdYYYY,
  2743.         where the separator, "d", is Delim[1].}
  2744.  
  2745.         Examples:
  2746.              See TESTDATE.PAS
  2747.  
  2748.         Comments:
  2749.  
  2750.         See also:
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778.  
  2779.  
  2780.  
  2781.  
  2782.  
  2783.  
  2784.  
  2785.  
  2786.  
  2787.  
  2788.  
  2789.                                   ShDatPk  5-12
  2790.                                                          03/25/92 01:54pm
  2791.  
  2792.  
  2793.  
  2794.  
  2795.  
  2796.  
  2797.                                     ShErrMsg
  2798.  
  2799.                          An Error Message Handeling Unit
  2800.  
  2801.  
  2802.         INTRODUCTION
  2803.              "Runtime error 152 at 12C4:0B23" really is not all that
  2804.         informative. How much better to see
  2805.  
  2806.                        Runtime error 152 - Drive not ready
  2807.                             Error at 1376:0003
  2808.  
  2809.              If ShErrMsg is included LAST in the USES statement of your
  2810.         program, any normal runtime errors will be reported along with a
  2811.         brief message suggesting the problem.
  2812.  
  2813.              During initialization, ShErrMsg installs a special exit
  2814.         routine into the exit procedure chain maintained by Turbo PASCAL.
  2815.         For the normal suite of runtime errors as listed in the manuals,
  2816.         this exit routine will display the error information in the ex-
  2817.         panded format shown above, with the explanatory message.
  2818.  
  2819.              Further, ShErrMsg interfaces replacements for T-PASCAL's
  2820.         HALT and RUNERROR procedures. These replacements, called HaltMsg
  2821.         and RunErrorMsg, permit the programmer to display any desired
  2822.         message along with the normal termination information reported by
  2823.         the corresponding T-PASCAL routine.
  2824.  
  2825.              ShErrMsg installs itself with checking ON; i.e., any errors
  2826.         occurring during execution of your program which would normally
  2827.         cause program termination will terminate with a message as de-
  2828.         scribed above. Should you wish it, you can turn this facility off
  2829.         and on again using the two procedures
  2830.  
  2831.                                      CheckOff
  2832.                                      CheckOn
  2833.  
  2834.              If CheckOff has been executed, error reporting will appear
  2835.         as if ShErrMsg had never been installed. The messages will not
  2836.         appear. HaltMsg and RunErrorMsg will behave exactly as if Halt or
  2837.         RunError had been called.
  2838.  
  2839.              If checking is enabled, either by default or through execu-
  2840.         tion of CheckOn, and procedure RunError is executed with an error
  2841.         code not part of the normal suite, the message "Unknown Error
  2842.         Code" will appear. RunErrorMsg will, of course, report whatever
  2843.         message you have provided as part of the call.
  2844.  
  2845.  
  2846.  
  2847.  
  2848.                                   ShErrMsg  6-1
  2849.  
  2850.  
  2851.  
  2852.         ERROR ADDRESS REPORTING
  2853.              If checking is enabled, or if RunErrorMsg is called (even if
  2854.         checking is disabled), the error address reported will appear
  2855.         slightly different than it normally would. ShErrMsg reports ad-
  2856.         dresses normalized; the segment address is adjusted so that the
  2857.         offset shown lies in the range
  2858.  
  2859.                                   0 <= Ofs <= $F
  2860.  
  2861.              If, however, you calculate the actual resulting 20-bit
  2862.         addresses, you will find that they are identical.
  2863.  
  2864.  
  2865.         INTERFACED ELEMENTS
  2866.  
  2867.         Routines
  2868.         ========
  2869.         ____________________________
  2870.         CHECKON
  2871.         CHECKOFF
  2872.  
  2873.         Declarations:
  2874.              procedure CheckOn;
  2875.              procedure CheckOff;
  2876.  
  2877.         Purpose:
  2878.              Enables/disables the error reporting facilities of ShErrMsg.
  2879.  
  2880.         Examples:
  2881.              ∙∙∙
  2882.              CheckOff; {Turn off error reporting}
  2883.              ∙∙∙
  2884.              CheckOn;  {Turn error reporting back on}
  2885.  
  2886.         Comment:
  2887.              The default state following initialization is CheckOn.
  2888.  
  2889.  
  2890.  
  2891.  
  2892.  
  2893.  
  2894.  
  2895.  
  2896.  
  2897.  
  2898.  
  2899.  
  2900.  
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.                                   ShErrMsg  6-2
  2907.  
  2908.  
  2909.  
  2910.         ____________________________
  2911.         HALTMSG
  2912.  
  2913.         Declarations:
  2914.              procedure HaltMsg(Code : word; Msg : string);
  2915.  
  2916.         Purpose:
  2917.              To stop execution of the program, returning an error code to
  2918.         DOS and optionally displaying a message.
  2919.  
  2920.         Examples:
  2921.              ∙∙∙
  2922.              HaltMsg(1000, 'Exiting on a problem in procedure FOO_BAZ');
  2923.  
  2924.         Comments:
  2925.              If Checking is ON, execution will stop with the message, and
  2926.         a return code of 1000 will be passed to DOS.
  2927.  
  2928.                     ErrorLevel 1000
  2929.                        Exiting on a problem in procedure FOO_BAZ
  2930.  
  2931.              If checking is OFF, execution will stop with no message, and
  2932.         a return code of 1000 will be passed to DOS.
  2933.  
  2934.              In either case, due to the way in which DOS is implemented,
  2935.         an
  2936.  
  2937.                                   IF ERRORLEVEL
  2938.  
  2939.         command will be sensitive ONLY TO THE LOW BYTE of the code. Thus,
  2940.         in the above example, DOS will see a return code of 232.
  2941.  
  2942.         See also:
  2943.              RunErrorMsg
  2944.  
  2945.  
  2946.  
  2947.  
  2948.  
  2949.  
  2950.  
  2951.  
  2952.  
  2953.  
  2954.  
  2955.  
  2956.  
  2957.  
  2958.  
  2959.  
  2960.  
  2961.  
  2962.  
  2963.  
  2964.                                   ShErrMsg  6-3
  2965.  
  2966.  
  2967.  
  2968.         ____________________________
  2969.         RUNERRORMSG
  2970.  
  2971.         Declarations:
  2972.              procedure RunErrorMsg(Code : integer; Msg : string);
  2973.  
  2974.         Purpose:
  2975.              To stop execution of the program with a runtime error
  2976.         message, optionally augmented by an additional information
  2977.         message, and returning an error code to DOS.
  2978.  
  2979.         Examples:
  2980.              ∙∙∙
  2981.              RunErrorMsg(1000, 'Problem in procedure FOO_BAZ');
  2982.  
  2983.         Comments:
  2984.              If Checking is ON, execution will stop with the following
  2985.         message, and a return code of 1000 will be passed to DOS.
  2986.  
  2987.                            Runtime error 1000 at 0C8F:0008
  2988.                               Problem in procedure FOO_BAZ
  2989.  
  2990.              If checking is OFF, execution will stop with the following
  2991.         message, and a return code of 1000 will be passed to DOS.
  2992.  
  2993.                            Runtime error 232 at 0000:C8F8
  2994.  
  2995.              In either case, due to the way in which DOS is implemented,
  2996.         an
  2997.  
  2998.                                   IF ERRORLEVEL
  2999.  
  3000.         command will be sensitive ONLY TO THE LOW BYTE of the code. Thus,
  3001.         in the above example, DOS will see a return code of 232.
  3002.  
  3003.              Note also that, if checking if turned off, the error address
  3004.         is not normalized.
  3005.  
  3006.         See also:
  3007.              HaltMsg
  3008.  
  3009.  
  3010.  
  3011.  
  3012.  
  3013.  
  3014.  
  3015.  
  3016.  
  3017.  
  3018.  
  3019.  
  3020.  
  3021.  
  3022.                                   ShErrMsg  6-4
  3023.                                                          03/25/92 01:54pm
  3024.  
  3025.  
  3026.  
  3027.  
  3028.  
  3029.  
  3030.                                      ShList
  3031.  
  3032.                              A List Manipulation Unit
  3033.  
  3034.  
  3035.         INTRODUCTION
  3036.              Lists, rings, and stacks are among the most common data
  3037.         structures used (after arrays). They are also probably among the
  3038.         worst offenders when it comes to "re-inventing the wheel." Many
  3039.         programmers build special purpose list manipulation routines each
  3040.         time a list is needed. Obviously, a generic list manipulation
  3041.         package is a valuable addition to the available "bag of tricks."
  3042.  
  3043.              ShList contains all of the routines necessary to establish
  3044.         and manipulate singly and doubly linked lists, rings, and stacks.
  3045.         The data associated with any given list, ring, or stack can be
  3046.         any standard or user defined data type. The structure of the data
  3047.         can change, but the total length of the data must remain con-
  3048.         stant. Thus, for example, variant records can be used.
  3049.  
  3050.              Stacks do not constitute a separate entity; their establish-
  3051.         ment and manipulation is accomplished by setting up a singly
  3052.         linked list, and restricting oneself to slPush and slPop respec-
  3053.         tively for data storage and retrieval.
  3054.  
  3055.              Rings also do not constitute a separate entity. Both the
  3056.         singly and doubly linked list are, in fact, treated as rings.
  3057.         When traversing a list of either type (e.g., using xxGetNext),
  3058.         retrieval will fail with the next call following retrieval of the
  3059.         last list element. If xxGetNext is called again, however, the
  3060.         element at the head of the list will be retrieved. Thus, the
  3061.         entity has all the functionality of a ring.
  3062.  
  3063.  
  3064.         NOMENCLATURE
  3065.              The names of the routines within ShList which apply to
  3066.         singly linked lists are prefixed with the letters "sl", as
  3067.         "slPut", "slAppend", etc. Those applying to doubly linked lists
  3068.         have a "dl" prefix.
  3069.  
  3070.              Many of the routines have identical functions, and differ
  3071.         only in the type of entity which they manipulate. Such routines
  3072.         have similar names, differing only in the prefix as described
  3073.         above; for example (slPut, dlPut), (slPush, dlPush). These will
  3074.         be discussed together in the following documentation.
  3075.  
  3076.  
  3077.  
  3078.  
  3079.  
  3080.  
  3081.                                    ShList  7-1
  3082.  
  3083.  
  3084.  
  3085.              In most cases, the call to a routine will have as one of its
  3086.         parameters an untyped "var" parameter called DataRec. The data to
  3087.         be placed on or retrieved from the list is passed to/from the
  3088.         routine through this parameter. Since it is an untyped parameter,
  3089.         it is up to you to make sure that the data being passed is of the
  3090.         proper length and structure. Examples are provided with the
  3091.         description of each routine.
  3092.  
  3093.  
  3094.                                !!CAUTIONARY NOTE!!
  3095.  
  3096.              MARK/RELEASE must not be used for heap management when
  3097.              using this unit. GETMEM/FREEMEM or NEW/DISPOSE must be
  3098.              used instead.
  3099.  
  3100.                            !!END OF CAUTIONARY NOTE!!
  3101.  
  3102.  
  3103.         INTERFACED ELEMENTS
  3104.  
  3105.         Types
  3106.         =====
  3107.              slNodePtr = ^slNode;
  3108.              slNode    = record
  3109.                            Data  : pointer;
  3110.                            Next  : slNodePtr;
  3111.                            end;
  3112.              dlNodePtr = ^dlNode;
  3113.              dlNode    = record
  3114.                            Data  : pointer;
  3115.                            Next,
  3116.                            Prev  : dlNodePtr;
  3117.                            end;
  3118.              These are the basic node structures of the nodes for singly
  3119.         and doubly linked nodes. They will be of no particular interest
  3120.         to you unless you need to modify the code of the unit.
  3121.  
  3122.  
  3123.  
  3124.  
  3125.  
  3126.  
  3127.  
  3128.  
  3129.  
  3130.  
  3131.  
  3132.  
  3133.  
  3134.  
  3135.  
  3136.  
  3137.  
  3138.  
  3139.                                    ShList  7-2
  3140.  
  3141.  
  3142.  
  3143.              slList    = record
  3144.                            DataRecSize : word;
  3145.                            Count       : LongInt;
  3146.                            Head,
  3147.                            Tail,
  3148.                            Current     : slNodePtr;
  3149.                            end;
  3150.              dlList    = record
  3151.                            DataRecSize : word;
  3152.                            Count       : LongInt;
  3153.                            Head,
  3154.                            Tail,
  3155.                            Current     : dlNodePtr;
  3156.                            end;
  3157.              These are the structures of the singly and doubly linked
  3158.         lists, respectively. You will be passing a variable of one of
  3159.         these types to almost all of the routines in the unit. The actual
  3160.         details of the structure need not concern you, however, unless
  3161.         you need to modify the code of the unit.
  3162.  
  3163.  
  3164.              dlLessFunc = function(var DataRec1, DataRec2)  : boolean;
  3165.              This is the form of a function which you will need to con-
  3166.         struct if you are using the dlPutSorted routine. It is used to
  3167.         determine the sort order of your data records. Its use is identi-
  3168.         cal in concept to the "less" function of the TurboSort, TpSort,
  3169.         or OpSort units.
  3170.  
  3171.  
  3172.  
  3173.  
  3174.  
  3175.  
  3176.  
  3177.  
  3178.  
  3179.  
  3180.  
  3181.  
  3182.  
  3183.  
  3184.  
  3185.  
  3186.  
  3187.  
  3188.  
  3189.  
  3190.  
  3191.  
  3192.  
  3193.  
  3194.  
  3195.  
  3196.  
  3197.                                    ShList  7-3
  3198.  
  3199.  
  3200.  
  3201.         Routines
  3202.         ========
  3203.              Many of the routines have identical functions, and differ
  3204.         only in the type of entity which they manipulate. These will be
  3205.         discussed together in the following documentation.
  3206.  
  3207.              The following routines are interfaced in ShList. They are
  3208.         arranged alphabetically by basic function or routine name.
  3209.  
  3210.         ____________________________
  3211.         APPEND
  3212.  
  3213.         Declarations:
  3214.              function slAppend(var L : slList; var DataRec) : boolean;
  3215.              function dlAppend(var L : dlList; var DataRec) : boolean;
  3216.  
  3217.         Purpose:
  3218.              Appends a data record to an existing list. If the list is
  3219.         empty, Append simply places the record in the list.
  3220.  
  3221.         Comments:
  3222.              The list must have been initialized prior to calling Append.
  3223.         Append returns a value of "false" if insufficient heap space is
  3224.         available for allocation of the node and data record.
  3225.  
  3226.         Example:
  3227.              if not slAppend(MyList, MyDataRecord) then begin
  3228.                {Execute your recovery code}
  3229.                end;
  3230.  
  3231.         See Also:
  3232.              Put, PutPrev, PutSorted, Push
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.  
  3239.  
  3240.  
  3241.  
  3242.  
  3243.  
  3244.  
  3245.  
  3246.  
  3247.  
  3248.  
  3249.  
  3250.  
  3251.  
  3252.  
  3253.  
  3254.  
  3255.                                    ShList  7-4
  3256.  
  3257.  
  3258.  
  3259.         ____________________________
  3260.         COUNT
  3261.  
  3262.         Declarations:
  3263.              function slCount(L : slList) : LongInt;
  3264.              function dlCount(L : dlList) : LongInt;
  3265.  
  3266.         Purpose:
  3267.              Returns the number of items currently in the list.
  3268.  
  3269.         Comments:
  3270.              The item count is maintained continuously within the list
  3271.         structure, so it is not necessary to scan the list in order to
  3272.         generate the count.
  3273.  
  3274.         Example:
  3275.              for T1 := 1 to slCount(MyList) do begin
  3276.                if slPop(MyList, MyDataRec) then ;
  3277.                (* Now process the record *)
  3278.                end; {for T1 := ...}
  3279.  
  3280.              This code will process each record in the list, and the list
  3281.         will be left empty on loop exit.
  3282.  
  3283.  
  3284.         ____________________________
  3285.         FREE
  3286.  
  3287.         Declarations:
  3288.              procedure slFree(var L : slList);
  3289.              procedure dlFree(var L : dlList);
  3290.  
  3291.         Purpose:
  3292.              Releases the heap space allocated for a list and its data.
  3293.  
  3294.         Comments:
  3295.              This procedure should be called as soon as you have com-
  3296.         pleted your operations on the specified list. The list must be
  3297.         re-initialized if it is to be reused.
  3298.  
  3299.         Example:
  3300.              slFree(MyList);
  3301.  
  3302.              All heap space associated with "MyList" is released, follow-
  3303.         ing which all the internal pointers of "MyList" are set to "nil"
  3304.         and the associated data record length is set to zero.
  3305.  
  3306.         See Also:
  3307.              Init
  3308.  
  3309.  
  3310.  
  3311.  
  3312.  
  3313.                                    ShList  7-5
  3314.  
  3315.  
  3316.  
  3317.         ____________________________
  3318.         GETCURRENT
  3319.  
  3320.         Declarations:
  3321.              function slGetCurrent(var L : slList;
  3322.                                                   var DataRec) : boolean;
  3323.              function dlGetCurrent(var L : dlList;
  3324.                                                   var DataRec) : boolean;
  3325.  
  3326.         Purpose:
  3327.              Returns the data record at the current node and does not
  3328.         move the node pointer. Returns a function value of false if the
  3329.         list is empty or the current node pointer is nil.
  3330.  
  3331.         Comments:
  3332.              This is essentially a "reread" operation. Normally, the cur-
  3333.         rent node pointer will have been positioned during the course of
  3334.         some other operation (e.g., GetFirst) and the data record will
  3335.         have been returned as a result of that prior operation.
  3336.  
  3337.         Example:
  3338.              if not slGetCurrent(MyList, MyDataRec) then begin
  3339.                {Trying to read an empty list.}
  3340.                end;
  3341.  
  3342.         See Also:
  3343.              GetFirst GetNext GetLast GetPrev
  3344.  
  3345.  
  3346.         ____________________________
  3347.         GETFIRST
  3348.  
  3349.         Declarations:
  3350.              function slGetFirst(var L : slList; var DataRec) : boolean;
  3351.              function dlGetFirst(var L : dlList; var DataRec) : boolean;
  3352.  
  3353.         Purpose:
  3354.              Returns the data record at the head of the list. Sets the
  3355.         current node pointer to the head of the list. Returns a function
  3356.         value of false if the list is empty.
  3357.  
  3358.         Comments:
  3359.  
  3360.         Example:
  3361.              if not slGetFirst(MyList, MyDataRec) then begin
  3362.                {Trying to read an empty list.}
  3363.                end;
  3364.  
  3365.         See Also:
  3366.              GetCurrent GetNext GetLast GetPrev
  3367.  
  3368.  
  3369.  
  3370.  
  3371.                                    ShList  7-6
  3372.  
  3373.  
  3374.  
  3375.         ____________________________
  3376.         GETLAST
  3377.  
  3378.         Declarations:
  3379.              function slGetLast(var L : slList; var DataRec) : boolean;
  3380.              function dlGetLast(var L : dlList; var DataRec) : boolean;
  3381.  
  3382.         Purpose:
  3383.              Returns the data record at the tail of the list. Sets the
  3384.         current node pointer to the tail of the list. Returns a function
  3385.         value of false if the list is empty.
  3386.  
  3387.         Comments:
  3388.  
  3389.         Example:
  3390.              if not slGetLast(MyList, MyDataRec) then begin
  3391.                {Trying to read an empty list.}
  3392.                end;
  3393.  
  3394.         See Also:
  3395.              GetCurrent GetFirst GetNext GetPrev
  3396.  
  3397.  
  3398.  
  3399.  
  3400.  
  3401.  
  3402.  
  3403.  
  3404.  
  3405.  
  3406.  
  3407.  
  3408.  
  3409.  
  3410.  
  3411.  
  3412.  
  3413.  
  3414.  
  3415.  
  3416.  
  3417.  
  3418.  
  3419.  
  3420.  
  3421.  
  3422.  
  3423.  
  3424.  
  3425.  
  3426.  
  3427.  
  3428.  
  3429.                                    ShList  7-7
  3430.  
  3431.  
  3432.  
  3433.         ____________________________
  3434.         GETNEXT
  3435.  
  3436.         Declarations:
  3437.              function slGetNext(var L : slList; var DataRec) : boolean;
  3438.              function dlGetNext(var L : dlList; var DataRec) : boolean;
  3439.  
  3440.         Purpose:
  3441.              Returns the next data record in the list. Sets the current
  3442.         node pointer to the record retrieved. Returns a function value of
  3443.         false if the list is empty or if the last record successfully
  3444.         retrieved was at the list tail. In this latter case, calling
  3445.         slGetNext or dlGetNext again will retrieve the head of the list.
  3446.  
  3447.         Comments:
  3448.  
  3449.         Example:
  3450.           {The following example assumes boolean short-circuiting ($B+)}
  3451.              if (not slGetNext(MyList, MyDataRec))
  3452.                {slGetNext false means an empty list or end of list}
  3453.                and slGetNext(MyList, MyDataRec) then begin
  3454.                {processing the head of the list}
  3455.                end
  3456.              else begin
  3457.                {processing the normal "next" element in the list}
  3458.                end;
  3459.  
  3460.         See Also:
  3461.              GetCurrent GetFirst GetLast GetPrev
  3462.  
  3463.  
  3464.  
  3465.  
  3466.  
  3467.  
  3468.  
  3469.  
  3470.  
  3471.  
  3472.  
  3473.  
  3474.  
  3475.  
  3476.  
  3477.  
  3478.  
  3479.  
  3480.  
  3481.  
  3482.  
  3483.  
  3484.  
  3485.  
  3486.  
  3487.                                    ShList  7-8
  3488.  
  3489.  
  3490.  
  3491.         ____________________________
  3492.         GETPREV
  3493.  
  3494.         Declarations:
  3495.              function dlGetPrev(var L : dlList; var DataRec) : boolean;
  3496.  
  3497.         Purpose:
  3498.              Same as dlGetNext, but in the opposite direction. Returns
  3499.         the previous data record in the list. Sets the current node
  3500.         pointer to the record retrieved. Returns a function value of
  3501.         false if the list is empty or if the last record successfully
  3502.         retrieved was at the list head. In this latter case, calling
  3503.         dlGetPrev again will retrieve the tail of the list.
  3504.  
  3505.         Comments:
  3506.              Note that the GetPrev operation can only be performed on
  3507.         doubly linked lists. There is no equivalent operation for singly
  3508.         linked lists.
  3509.  
  3510.         Example:
  3511.           {The following example assumes boolean short-circuiting ($B+)}
  3512.              if (not dlGetPrev(MyList, MyDataRec))
  3513.                {dlGetPrev false means an empty list or top of list}
  3514.                and dlGetPrev(MyList, MyDataRec) then begin
  3515.                {processing the tail of the list}
  3516.                end
  3517.              else begin
  3518.                {processing the normal "prior" element in the list}
  3519.                end;
  3520.  
  3521.         See Also:
  3522.              GetCurrent GetFirst GetLast GetNext
  3523.  
  3524.  
  3525.  
  3526.  
  3527.  
  3528.  
  3529.  
  3530.  
  3531.  
  3532.  
  3533.  
  3534.  
  3535.  
  3536.  
  3537.  
  3538.  
  3539.  
  3540.  
  3541.  
  3542.  
  3543.  
  3544.  
  3545.                                    ShList  7-9
  3546.  
  3547.  
  3548.  
  3549.         ____________________________
  3550.         LISTINIT
  3551.  
  3552.         Declarations:
  3553.              procedure slListInit(var L : slList; RecSize : word);
  3554.              procedure dlListInit(var L : dlList; RecSize : word);
  3555.  
  3556.         Purpose:
  3557.              Initializes a singly or doubly linked list, as appropriate.
  3558.  
  3559.         Comments:
  3560.              The list initialization routines initialize only the vari-
  3561.         ables of type slList or dlList. They perform no memory alloca-
  3562.         tion. Memory allocation is performed only by the various PUT
  3563.         routines.
  3564.  
  3565.              The ListInit routines **must** be called before any attempt
  3566.         is made to place any data in, or retrieve any data from any
  3567.         LIST-type variable. Also, once an initialized list has received
  3568.         data, ListInit **must not** be called prior to a call to Free.
  3569.         Failure to observe either of these warnings will produce
  3570.         unpredictable but probably disastrous results.
  3571.  
  3572.         Example:
  3573.              slListInit(MyList);
  3574.  
  3575.         See Also:
  3576.              Free
  3577.  
  3578.  
  3579.  
  3580.  
  3581.  
  3582.  
  3583.  
  3584.  
  3585.  
  3586.  
  3587.  
  3588.  
  3589.  
  3590.  
  3591.  
  3592.  
  3593.  
  3594.  
  3595.  
  3596.  
  3597.  
  3598.  
  3599.  
  3600.  
  3601.  
  3602.  
  3603.                                    ShList  7-10
  3604.  
  3605.  
  3606.  
  3607.         ____________________________
  3608.         POP
  3609.  
  3610.         Declarations:
  3611.              function slPop(var L : slList; var DataRec) : boolean;
  3612.              function dlPop(var L : dlList; var DataRec) : boolean;
  3613.  
  3614.         Purpose:
  3615.              Returns the data record at the head of the list, then deal-
  3616.         locates the space associated with the data record and node. Re-
  3617.         turns a function value of false if the list is empty.
  3618.  
  3619.         Comments:
  3620.  
  3621.         Example:
  3622.              while slPop(MyList, MyDataRec) do begin
  3623.                {process the retrieved record}
  3624.                end;
  3625.  
  3626.              This code will retrieve each record on the list and free up
  3627.         the space associated with each, as it is retrieved. You will end
  3628.         up with an empty list.
  3629.  
  3630.         See Also:
  3631.              Push Free
  3632.  
  3633.  
  3634.         ____________________________
  3635.         PUSH
  3636.  
  3637.         Declarations:
  3638.              function slPush(var L : slList; var DataRec) : boolean;
  3639.              function dlPush(var L : dlList; var DataRec) : boolean;
  3640.  
  3641.         Purpose:
  3642.              Pushes a data record onto the top of the list. Returns a
  3643.         function value of false if there is insufficient heap space to
  3644.         accommodate the list node and data record.
  3645.  
  3646.         Comments:
  3647.  
  3648.         Example:
  3649.              if not slPush(MyList, MyDataRec) then begin
  3650.                {perform recovery operations}
  3651.                end;
  3652.  
  3653.         See Also:
  3654.              Append Put PutPrev PutSorted Pop
  3655.  
  3656.  
  3657.  
  3658.  
  3659.  
  3660.  
  3661.                                    ShList  7-11
  3662.  
  3663.  
  3664.  
  3665.         ____________________________
  3666.         PUT
  3667.  
  3668.         Declarations:
  3669.              function slPut(var L : slList; var DataRec) : boolean;
  3670.              function dlPut(var L : dlList; var DataRec) : boolean;
  3671.  
  3672.         Purpose:
  3673.              Inserts a data record following the current node; returns
  3674.         with current pointer directed to the new node. Returns a function
  3675.         value of false if there is insufficient heap space to accommodate
  3676.         the list node and data record.
  3677.  
  3678.         Comments:
  3679.  
  3680.         Example:
  3681.              if not slPut(MyList, MyDataRec) then begin
  3682.                {perform recovery operations}
  3683.                end;
  3684.  
  3685.         See Also:
  3686.              Append Push PutPrev PutSorted Pop
  3687.  
  3688.  
  3689.         ____________________________
  3690.         PUTPREV
  3691.  
  3692.         Declarations:
  3693.              function dlPutPrev(var L : dlList; var DataRec) : boolean;
  3694.  
  3695.         Purpose:
  3696.              Inserts a data record ahead of the current node; returns
  3697.         with current pointer directed to the new node. Returns a function
  3698.         value of false if there is insufficient heap space to accommodate
  3699.         the list node and data record.
  3700.  
  3701.         Comments:
  3702.              Note that the PutPrev operation can only be performed on
  3703.         doubly linked lists. There is no equivalent operation for singly
  3704.         linked lists.
  3705.  
  3706.         Example:
  3707.              if not dlPutPrev(MyList, MyDataRec) then begin
  3708.                {perform recovery operations}
  3709.                end;
  3710.  
  3711.         See Also:
  3712.              Append GetPrev Push Put PutSorted
  3713.  
  3714.  
  3715.  
  3716.  
  3717.  
  3718.  
  3719.                                    ShList  7-12
  3720.  
  3721.  
  3722.  
  3723.         ____________________________
  3724.         PUTSORTED
  3725.  
  3726.         Declarations:
  3727.              function dlPutSorted(var L : dlList; var DataRec;
  3728.                                            Less : dlLessFunc) : boolean;
  3729.         Purpose:
  3730.              Inserts a data record into the list in sorted order, as
  3731.         determined by the user-defined boolean function LESS. Returns a
  3732.         function value of false if there is insufficient heap space to
  3733.         accommodate the list node and data record.
  3734.  
  3735.         Comments:
  3736.              The function LESS is a user-defined boolean function whose
  3737.         declaration **must** be of the form
  3738.  
  3739.              function Less(var Rec1, Rec2) :boolean;
  3740.  
  3741.         and **must** be compiled under the FAR model.
  3742.  
  3743.              Note that the PutSorted operation can only be performed on
  3744.         doubly linked lists. There is no equivalent operation for singly
  3745.         linked lists.
  3746.  
  3747.              Note also that, to build the sorted list in descending order
  3748.         rather than ascending, it is only necessary to reverse the sense
  3749.         of the inequality in the comparison function.
  3750.  
  3751.         Example:
  3752.              {$F+}
  3753.              function MyLess(var MyRec1, MyRec2) : boolean;
  3754.                begin
  3755.                  MyLess := (MyRecType(MyRec1).FieldA <
  3756.                              MyRecType(MyRec2).FieldA);
  3757.                  end;
  3758.              {$F-}
  3759.              ...
  3760.              if not dlPutSorted(MyList, MyDataRec, @MyLess) then begin
  3761.                {do something}
  3762.                end;
  3763.              Incorrect!!! The @-symbol cannot be used here.
  3764.  
  3765.              if not dlPutSorted(MyList, MyDataRec, MyLess) then begin
  3766.                {do something}
  3767.                end;
  3768.              Correct. Only the function name is passed.
  3769.  
  3770.         See Also:
  3771.              Append GetPrev Push Put PutPrev
  3772.  
  3773.  
  3774.  
  3775.  
  3776.  
  3777.                                    ShList  7-13
  3778.  
  3779.  
  3780.  
  3781.         ____________________________
  3782.         SPACEUSED
  3783.  
  3784.         Declarations:
  3785.              function slSpaceUsed(L : slList) : LongInt;
  3786.              function dlSpaceUsed(L : dlList) : LongInt;
  3787.  
  3788.         Purpose:
  3789.              Returns the total amount of heap space currently allocated
  3790.         to the list and its data.
  3791.  
  3792.         Comments:
  3793.  
  3794.         Example:
  3795.              WriteLn(slSpaceUsed(MyList), ' total bytes used');
  3796.  
  3797.         See Also:
  3798.              Count
  3799.  
  3800.  
  3801.  
  3802.  
  3803.  
  3804.  
  3805.  
  3806.  
  3807.  
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.  
  3814.  
  3815.  
  3816.  
  3817.  
  3818.  
  3819.  
  3820.  
  3821.  
  3822.  
  3823.  
  3824.  
  3825.  
  3826.  
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832.  
  3833.  
  3834.  
  3835.                                    ShList  7-14
  3836.                                                          03/25/92 01:54pm
  3837.  
  3838.  
  3839.  
  3840.  
  3841.  
  3842.  
  3843.                                     ShLngStr
  3844.  
  3845.                          A Long String Manipulation Unit
  3846.  
  3847.  
  3848.         INTRODUCTION
  3849.              ShLngStr is a unit which provides the ability to manipulate
  3850.         long strings (up to 65517 characters in length) using Turbo Pas-
  3851.         cal. As such, it owes a debt to the Tp/OpASCIIZ units published
  3852.         by TurboPower Software. Unlike the ASCIIZ manipulation units,
  3853.         however, it carries its dynamic string length information in a
  3854.         WORD at the beginning of the string. As such, it owes a debt to
  3855.         the TpWrdStr unit written by Ken Henderson.
  3856.  
  3857.              Both TpWrdStr and Tp/OpASCIIZ require a careful tradeoff on
  3858.         the part of the user. They both typically allocate an "array of
  3859.         char" in the data segment, in which the string data are stored;
  3860.         thus they both define a MaxSize constant which must be carefully
  3861.         balanced between providing a maximum string length long enough to
  3862.         get the job done, and one which is small enough to avoid using up
  3863.         the entire data segment.
  3864.  
  3865.              ShLngStr avoids this problem. ShLngStr stores all of its
  3866.         string data on the heap. When a variable is declared to be of
  3867.         type LongString, this declaration establishes only a pointer in
  3868.         the data segment. The LongString must then be initialized prior
  3869.         to use. This initialization establishes a maximum allowable
  3870.         string length, which may now vary from one LongString to the
  3871.         next. Only the amount of heap space required for the initialized
  3872.         maximum length is used. In this respect, the analog of a string
  3873.         declaration of, for example, "var string[127];" has been pre-
  3874.         served. Any of the procedures and functions in this unit will
  3875.         observe the "declared" maximum length, and will adjust their
  3876.         behavior appropriately
  3877.  
  3878.              Thus, although a MaxLongString constant is included in the
  3879.         unit, its value is set to the maximum allowable value (65517) and
  3880.         is used only by lsInit.
  3881.  
  3882.              Notwithstanding any of the above, the code in ShLngStr is
  3883.         completely our own. Any bugs or deficiencies cannot be blamed on
  3884.         anyone other than Madison & Associates.
  3885.  
  3886.  
  3887.  
  3888.  
  3889.  
  3890.  
  3891.  
  3892.  
  3893.  
  3894.                                   ShLngStr  8-1
  3895.  
  3896.  
  3897.  
  3898.         OVERVIEW
  3899.              There are currently approximately 80 procedures and func-
  3900.         tions available within the ShLngStr unit. With few exceptions,
  3901.         each procedure has a corresponding function; e.g., procedure
  3902.         lsStr2LongString which converts a string to a LongString has a
  3903.         corresponding function lsStr2LongStringF. It is important to
  3904.         remember that the functions which return a LongString are return-
  3905.         ing a pointer value rather than the contents of the LongString
  3906.         itself. Failure to account for this can result in rather startl-
  3907.         ing results on occasion.
  3908.  
  3909.              Function results (i.e., these pointers) are stored in a ring
  3910.         buffer which is allocated as needed, and is only reallocated when
  3911.         the ring pointer comes back around to the specific element. By
  3912.         default, the number of elements in the ring is set to 25. This
  3913.         should be sufficient for most purposes; should it prove insuffi-
  3914.         cient, set the typed constant RingSize to a larger value and re-
  3915.         compile. Alternatively, RingSize can be increased at execution
  3916.         time to a maximum value of 100; it should NOT be decreased at
  3917.         execution time, however. It can be set to a maximum of 100
  3918.         without affecting the size of the data segment.
  3919.  
  3920.              Since the data associated with function (pointer) returns
  3921.         are accessible only through elements in the ring buffer, and
  3922.         since the heap space used to store these data will be released
  3923.         when the ring element is required for reuse, it is important that
  3924.         these data be used as quickly as possible. They ain't gonna be
  3925.         around forever!
  3926.  
  3927.              Thus, the rule of thumb should be "when in doubt, use
  3928.         procedure calls."
  3929.  
  3930.                                !!CAUTIONARY NOTE!!
  3931.  
  3932.              MARK/RELEASE must not be used for heap management when
  3933.              using this unit. GETMEM/FREEMEM or NEW/DISPOSE must be
  3934.              used instead.
  3935.  
  3936.                            !!END OF CAUTIONARY NOTE!!
  3937.  
  3938.  
  3939.  
  3940.  
  3941.  
  3942.  
  3943.  
  3944.  
  3945.  
  3946.  
  3947.  
  3948.  
  3949.  
  3950.  
  3951.  
  3952.                                   ShLngStr  8-2
  3953.  
  3954.  
  3955.  
  3956.         INTERFACED ELEMENTS
  3957.  
  3958.         Types
  3959.         =====
  3960.  
  3961.              NOTE: Because of the way in which LongStringType is
  3962.              defined, if the ShLngStr unit is recompiled, range
  3963.              checking MUST be turned off ({$R-}). Note also that
  3964.              redefining the lsData field as array[1..MaxLongString]
  3965.              is apt to cause other problems. This redefinition is
  3966.              definitely NOT RECOMMENDED!
  3967.  
  3968.              LongStringType  = record
  3969.                                  Length,           {Dynamic length}
  3970.                                  dLength : word;   {"Declared" length}
  3971.                                  lsData  : array[1..1] of char;
  3972.                                  end;
  3973.              The record structure allocated on the heap for the storage
  3974.         of LongString data.
  3975.  
  3976.              LongString      = ^LongStringType;
  3977.              The type expected as actual parameters to the routines in
  3978.         this unit; also, the type returned by most of the functions.
  3979.  
  3980.              lsCompType      = (Less, Equal, Greater);
  3981.              The type returned by the LongString comparison functions.
  3982.  
  3983.              lsDelimSetType  = set of char;
  3984.              The type of the set of characters which the GetNext routines
  3985.         will use as word delimiters.
  3986.  
  3987.  
  3988.         Constants
  3989.         =========
  3990.              RingSize : byte = 25;
  3991.              The number of elements in the ring buffer, used to store
  3992.         pointers returned by function calls of type LongString. This
  3993.         value may be freely increased to a maximum value of 100 during
  3994.         program execution, if necessary. Decreasing it, however, could
  3995.         result in orphan blocks allocated on the heap, with no way to
  3996.         recover them.
  3997.  
  3998.              lsDelimSet  : lsDelimSetType = [#0..#32];
  3999.              The typed constant used by the GetNext routines to determine
  4000.         the end of a substring to be returned. It may be freely changed
  4001.         during program execution.
  4002.  
  4003.  
  4004.  
  4005.  
  4006.  
  4007.  
  4008.  
  4009.  
  4010.                                   ShLngStr  8-3
  4011.  
  4012.  
  4013.  
  4014.              MaxLongString = 65517;
  4015.              The maximum length of a LongString.
  4016.  
  4017.              NotFound = 0;
  4018.              Returned by the lsPos functions if a substring is not found.
  4019.  
  4020.  
  4021.         Nomenclature
  4022.         ============
  4023.              All interfaced routines in ShLngStr have "ls" as the first
  4024.         two characters of their name.
  4025.  
  4026.              In the descriptive listings which follow, all routines hav-
  4027.         ing similar functionality are grouped, and all routines within a
  4028.         group have names which differ only in their respective suffixes;
  4029.         e.g.,
  4030.  
  4031.                         lsDelAll
  4032.                         lsDelAllF
  4033.                         lsDelAllStr
  4034.                         lsDelAllStrF
  4035.                         lsDelAllUC
  4036.                         lsDelAllUCF
  4037.                         lsDelAllStrUC
  4038.                         lsDelAllStrUCF
  4039.  
  4040.              These routines delete all occurrences of an entity from a
  4041.         LongString. The basic procedure, lsDelAll, takes three parameters
  4042.         of type LongString; respectively, the input LongString containing
  4043.         the data to be scanned, the input LongString containing the
  4044.         entity to be deleted from the first, and the output LongString
  4045.         which is a copy of the input data LongString with all occurrences
  4046.         of the second parameter deleted.
  4047.  
  4048.              The "F" suffixes on the second, fourth, sixth, and eighth
  4049.         names indicate a function call returning the output LongString.
  4050.  
  4051.              The "Str" suffix on the third, fourth, seventh, and eighth
  4052.         names indicates that the entity to be deleted is a string rather
  4053.         than a LongString.
  4054.  
  4055.              The "UC" suffix on the fifth through the eighth names
  4056.         indicate that searching and deletion will be performed all in
  4057.         upper case; the searching will not be case sensitive.
  4058.  
  4059.              Some functions exist which do not have the "F" suffix. In
  4060.         each such case, the returned value is a normal Turbo Pascal data
  4061.         type, specifically, WORD or STRING.
  4062.  
  4063.              In the following, the ordering is alphabetic by primary
  4064.         routine name.
  4065.  
  4066.  
  4067.  
  4068.                                   ShLngStr  8-4
  4069.  
  4070.  
  4071.  
  4072.         Routines
  4073.         ========
  4074.         ____________________________
  4075.         lsCENTER
  4076.  
  4077.         Declarations:
  4078.              procedure lsCenter
  4079.                   (A: LongString; Width: word; B: LongString);
  4080.              function lsCenterF
  4081.                   (A: LongString; Width: word): LongString;
  4082.  
  4083.         Purpose:
  4084.              Return a LongString centered in a LongString of blanks with
  4085.         specified width.
  4086.  
  4087.         Examples:
  4088.              If             A contains "abcdefg"
  4089.              then           lsCenter(A, 13, B);
  4090.              results in     B containing "   abcdefg   "
  4091.  
  4092.         Comments:
  4093.              If the length of A already exceeds Width, A will be returned
  4094.         unchanged.
  4095.  
  4096.         See Also:
  4097.              lsCenterCh
  4098.  
  4099.  
  4100.  
  4101.  
  4102.  
  4103.  
  4104.  
  4105.  
  4106.  
  4107.  
  4108.  
  4109.  
  4110.  
  4111.  
  4112.  
  4113.  
  4114.  
  4115.  
  4116.  
  4117.  
  4118.  
  4119.  
  4120.  
  4121.  
  4122.  
  4123.  
  4124.  
  4125.  
  4126.                                   ShLngStr  8-5
  4127.  
  4128.  
  4129.  
  4130.         ____________________________
  4131.         lsCENTERCH
  4132.  
  4133.         Declarations:
  4134.              procedure lsCenterCh
  4135.                   (A: LongString; Ch: Char; Width: word; B: LongString);
  4136.              function lsCenterChF
  4137.                   (A: LongString; Ch: Char; Width: word): LongString;
  4138.  
  4139.         Purpose:
  4140.              Return a LongString centered in a LongString of Ch with spe-
  4141.         cified width.
  4142.  
  4143.         Examples:
  4144.              If             A contains "abcdefg"
  4145.              then           lsCenterCh(A, '+', 13, B);
  4146.              results in     B containing "+++abcdefg+++"
  4147.  
  4148.         Comments:
  4149.              If the length of A already exceeds Width, A will be returned
  4150.         unchanged.
  4151.  
  4152.         See Also:
  4153.              lsCenter
  4154.  
  4155.  
  4156.         ____________________________
  4157.         lsCHARSTR
  4158.  
  4159.         Declarations:
  4160.              procedure lsCharStr
  4161.                   (Ch: Char; Len: word; A: LongString);
  4162.              function lsCharStrF
  4163.                   (Ch: Char; Len: word): LongString;
  4164.  
  4165.         Purpose:
  4166.              Return a LongString of length Len filled with Ch.
  4167.  
  4168.         Examples:
  4169.              The call       lsCharStr('+', 10, A);
  4170.              results in     A containing "++++++++++"
  4171.  
  4172.         Comments:
  4173.              If Len is greater than the maximum length of A, the returned
  4174.         LongString will be equal in length to the maximum length of A.
  4175.  
  4176.         See Also:
  4177.  
  4178.  
  4179.  
  4180.  
  4181.  
  4182.  
  4183.  
  4184.                                   ShLngStr  8-6
  4185.  
  4186.  
  4187.  
  4188.         ____________________________
  4189.         lsCOMP
  4190.  
  4191.         Declarations:
  4192.              function lsComp
  4193.                   (A1, A2: LongString): lsCompType;
  4194.  
  4195.         Purpose:
  4196.              Compares A1 to A2, returning LESS, EQUAL, or GREATER.
  4197.  
  4198.         Examples:
  4199.                 For a normal COMPARE,
  4200.                         case lsComp(LS1, LS2) of
  4201.                           LESS    : {Do This}
  4202.                           EQUAL   : {Do That}
  4203.                           GREATER : {Do The Other}
  4204.                           end; {case lsComp}
  4205.  
  4206.                 For a case-insensitive COMPARE,
  4207.                         case lsComp(lsUpcaseF(LS1), lsUpcaseF(LS2)) of
  4208.                           LESS    : {Do This}
  4209.                           EQUAL   : {Do That}
  4210.                           GREATER : {Do The Other}
  4211.                           end; {case lsComp}
  4212.  
  4213.         Comments:
  4214.              This function completely implements the analog of the string
  4215.         comparison operators of Turbo Pascal.
  4216.  
  4217.         See Also:
  4218.  
  4219.  
  4220.  
  4221.  
  4222.  
  4223.  
  4224.  
  4225.  
  4226.  
  4227.  
  4228.  
  4229.  
  4230.  
  4231.  
  4232.  
  4233.  
  4234.  
  4235.  
  4236.  
  4237.  
  4238.  
  4239.  
  4240.  
  4241.  
  4242.                                   ShLngStr  8-7
  4243.  
  4244.  
  4245.  
  4246.         ____________________________
  4247.         lsCONCAT
  4248.  
  4249.         Declarations:
  4250.              procedure lsConcat
  4251.                   (A, B, C: LongString);
  4252.              function lsConcatF
  4253.                   (A, B: LongString): LongString;
  4254.              procedure lsConcatLs2Str
  4255.                   (S: string; A: LongString; C: LongString);
  4256.              function lsConcatLs2StrF
  4257.                   (S: string; A: LongString): LongString;
  4258.              procedure lsConcatStr2Ls
  4259.                   (A: LongString; S: string; C: LongString);
  4260.              function lsConcatStr2LsF
  4261.                   (A: LongString; S: string): LongString;
  4262.  
  4263.         Purpose:
  4264.              Concatenate the second parameter to the end of the first.
  4265.  
  4266.         Examples:
  4267.              If             A contains "abcdefg"
  4268.              and            B contains "hijklmn"
  4269.              then           lsConcat(A, B, C);
  4270.              results in     C containing "abcdefghijklmn"
  4271.  
  4272.         Comments:
  4273.  
  4274.         See Also:
  4275.  
  4276.  
  4277.  
  4278.  
  4279.  
  4280.  
  4281.  
  4282.  
  4283.  
  4284.  
  4285.  
  4286.  
  4287.  
  4288.  
  4289.  
  4290.  
  4291.  
  4292.  
  4293.  
  4294.  
  4295.  
  4296.  
  4297.  
  4298.  
  4299.  
  4300.                                   ShLngStr  8-8
  4301.  
  4302.  
  4303.  
  4304.         ____________________________
  4305.         lsCOPY
  4306.  
  4307.         Declarations:
  4308.              procedure lsCopy
  4309.                   (A: LongString; Start, Len: word; B: LongString);
  4310.              function lsCopyF
  4311.                   (A: LongString; Start, Len: word): LongString;
  4312.  
  4313.         Purpose:
  4314.              Return a LongString substring of A. The substring begins at
  4315.         position Start of A and will be of length Len.
  4316.  
  4317.         Examples:
  4318.              If             A contains "abcdefg"
  4319.              then           lsCopy(A, 4, 3, B);
  4320.              results in     B containing "def"
  4321.  
  4322.              If             A contains "abcdefg"
  4323.              then           lsCopy(A, 4, 10, B);
  4324.              results in     B containing "defg"
  4325.  
  4326.         Comments:
  4327.              Start=1 for first char in A.
  4328.  
  4329.              If Start > lsLength(A), an empty LongString will be
  4330.         returned.
  4331.  
  4332.              If Start+Len exceeds the length of A, the returned
  4333.         LongString will be of length lsLength(A)-Start+1.
  4334.  
  4335.         See Also:
  4336.  
  4337.  
  4338.  
  4339.  
  4340.  
  4341.  
  4342.  
  4343.  
  4344.  
  4345.  
  4346.  
  4347.  
  4348.  
  4349.  
  4350.  
  4351.  
  4352.  
  4353.  
  4354.  
  4355.  
  4356.  
  4357.  
  4358.                                   ShLngStr  8-9
  4359.  
  4360.  
  4361.  
  4362.         ____________________________
  4363.         lsCOUNT
  4364.  
  4365.         Declarations:
  4366.              function lsCount
  4367.                   (A, Obj: LongString):  word;
  4368.              function lsCountStr
  4369.                   (A: LongString; Obj: string): word;
  4370.              function lsCountStrUC
  4371.                   (A: LongString; Obj: string): word;
  4372.              function lsCountUC
  4373.                   (A, Obj: LongString):  word;
  4374.  
  4375.         Purpose:
  4376.              Returns the total number of non-overlapping occurrences of
  4377.         Obj in A.
  4378.  
  4379.         Examples:
  4380.              if lsCountStrUC(MyLS, 'abc') <> NotFound then {Do something}
  4381.  
  4382.              If             A contains "abcdeabcdeabcde"
  4383.              and            Obj contains "BCD"
  4384.              then           lsCount(A, Obj)
  4385.              returns        NotFound ( = 0 )
  4386.              but            lsCountUC(A, Obj)
  4387.              returns        3
  4388.  
  4389.         Comments:
  4390.              If Obj is not a substring of A, returns NotFound (i.e., 0).
  4391.  
  4392.         See Also:
  4393.  
  4394.  
  4395.  
  4396.  
  4397.  
  4398.  
  4399.  
  4400.  
  4401.  
  4402.  
  4403.  
  4404.  
  4405.  
  4406.  
  4407.  
  4408.  
  4409.  
  4410.  
  4411.  
  4412.  
  4413.  
  4414.  
  4415.  
  4416.                                   ShLngStr  8-10
  4417.  
  4418.  
  4419.  
  4420.         ____________________________
  4421.         lsDELALL
  4422.  
  4423.         Declarations:
  4424.              procedure lsDelAll
  4425.                   (A, Obj, B: LongString);
  4426.              function lsDelAllF
  4427.                   (A, Obj: LongString):  LongString;
  4428.              procedure lsDelAllStr
  4429.                   (A: LongString; Obj: string; B: LongString);
  4430.              function lsDelAllStrF
  4431.                   (A: LongString; Obj: string): LongString;
  4432.              procedure lsDelAllStrUC
  4433.                   (A: LongString; Obj: string; B: LongString);
  4434.              function lsDelAllStrUCF
  4435.                   (A: LongString; Obj: string): LongString;
  4436.              procedure lsDelAllUC
  4437.                   (A, Obj, B: LongString);
  4438.              function lsDelAllUCF
  4439.                   (A, Obj: LongString):  LongString;
  4440.  
  4441.         Purpose:
  4442.              Deletes all occurrences of Obj in A.
  4443.  
  4444.         Examples:
  4445.              See below.
  4446.  
  4447.         Comments:
  4448.              Should the deletion of Obj from A result in a new occurrence
  4449.         of Obj in A, the new occurrence will not be deleted, e.g.,
  4450.  
  4451.              If             A contains 'aabcbcabcd'
  4452.              and            Obj contains 'abc'
  4453.              then           lsDelAll(A, Obj, B);
  4454.              results in     B containing 'abcd'
  4455.              and not        'd'
  4456.  
  4457.              To delete all occurrences including such incidental
  4458.         occurrences, one would use, e.g.,
  4459.  
  4460.                             repeat
  4461.                               lsDelAll(A, Obj, A);
  4462.                               until lsCount(A, Obj) = 0;
  4463.  
  4464.         See Also:
  4465.              lsRepAll   lsCount
  4466.  
  4467.  
  4468.  
  4469.  
  4470.  
  4471.  
  4472.  
  4473.  
  4474.                                   ShLngStr  8-11
  4475.  
  4476.  
  4477.  
  4478.         ____________________________
  4479.         lsDELETE
  4480.  
  4481.         Declarations:
  4482.              procedure lsDelete
  4483.                   (A: LongString; Start, Len: word; B: LongString);
  4484.              function lsDeleteF
  4485.                   (A: LongString; Start, Len: word): LongString;
  4486.  
  4487.         Purpose:
  4488.              Delete Len characters of A, starting at position Start.
  4489.  
  4490.         Examples:
  4491.              If             A contains "abcdefg"
  4492.              then           lsDelete(A, 4, 3, B);
  4493.              results in     B containing "abcg"
  4494.  
  4495.              If             A contains "abcdefg"
  4496.              then           lsDelete(A, 4, 10, B);
  4497.              results in     B containing "abc"
  4498.  
  4499.         Comments:
  4500.              If Start is greater than the length of A, B = A on output.
  4501.  
  4502.         See Also:
  4503.              lsDelAll   lsRepAll
  4504.  
  4505.  
  4506.         ____________________________
  4507.         lsDISPOSE
  4508.  
  4509.         Declarations:
  4510.              procedure lsDispose
  4511.                   (var A: LongString);
  4512.  
  4513.         Purpose:
  4514.              Dispose of A, releasing its heap space.
  4515.  
  4516.         Examples:
  4517.              The call       lsDispose(A);
  4518.              results in     All heap space associated with A is released
  4519.              and            A = nil
  4520.  
  4521.         Comments:
  4522.  
  4523.         See Also:
  4524.              lsInit
  4525.  
  4526.  
  4527.  
  4528.  
  4529.  
  4530.  
  4531.  
  4532.                                   ShLngStr  8-12
  4533.  
  4534.  
  4535.  
  4536.         ____________________________
  4537.         lsGETNEXT
  4538.  
  4539.         Declarations:
  4540.              procedure lsGetNext
  4541.                   (LS1, LS2: LongString);
  4542.              function lsGetNextF
  4543.                   (LS1: LongString): LongString;
  4544.              procedure lsGetNextStr
  4545.                   (LS1: LongString; var S2: string);
  4546.              function lsGetNextStrF
  4547.                   (LS1: LongString): string;
  4548.  
  4549.         Purpose:
  4550.              Returns the next substring of LS1 which is delimited by a
  4551.         member of lsDelimSet.
  4552.  
  4553.         Examples:
  4554.              If             A contains "abc def ghi jkl"
  4555.              then the two calls
  4556.                             lsGetNext(A, B);
  4557.                             lsGetNext(A, B);
  4558.              result in      A containing " ghi jkl"
  4559.              and            B containing "def"
  4560.  
  4561.         Comments:
  4562.              On return, LS1 is returned untrimmed, but with the first
  4563.         matching substring deleted.
  4564.  
  4565.         See Also:
  4566.  
  4567.  
  4568.  
  4569.  
  4570.  
  4571.  
  4572.  
  4573.  
  4574.  
  4575.  
  4576.  
  4577.  
  4578.  
  4579.  
  4580.  
  4581.  
  4582.  
  4583.  
  4584.  
  4585.  
  4586.  
  4587.  
  4588.  
  4589.  
  4590.                                   ShLngStr  8-13
  4591.  
  4592.  
  4593.  
  4594.         ____________________________
  4595.         lsINIT
  4596.  
  4597.         Declarations:
  4598.              function lsInit
  4599.                   (var A: LongString; L: word): boolean;
  4600.  
  4601.         Purpose:
  4602.              "Declares" a LongString of maximum declared length L and
  4603.         establishes space for it on the heap.
  4604.  
  4605.         Examples:
  4606.              The call       if lsInit(A, 750) then {Do something};
  4607.              results in     a. A returned function value of "true"
  4608.                             b. 754 bytes being allocated on the heap.
  4609.                                (750 bytes for the character string,
  4610.                                 4 overhead bytes.)
  4611.                             c. A containing a pointer to the heap space.
  4612.  
  4613.              The call       lsInit(A, 65518);   {MaxLongString = 65517}
  4614.              results in     a. A returned function value of "false"
  4615.                             b. No space allocation on the heap.
  4616.                             c. A = nil
  4617.  
  4618.         Comments:
  4619.              Returns false if L is greater than MaxLongString.
  4620.  
  4621.              If there is insufficient heap space to accommodate the
  4622.         LongString, the program will terminate with a run-time error of
  4623.         250 (if lsInit has been called directly) or 251 (if lsInit has
  4624.         been called while attempting to allocate space on the ring
  4625.         buffer.
  4626.  
  4627.         See Also:
  4628.              lsDispose
  4629.  
  4630.  
  4631.  
  4632.  
  4633.  
  4634.  
  4635.  
  4636.  
  4637.  
  4638.  
  4639.  
  4640.  
  4641.  
  4642.  
  4643.  
  4644.  
  4645.  
  4646.  
  4647.  
  4648.                                   ShLngStr  8-14
  4649.  
  4650.  
  4651.  
  4652.         ____________________________
  4653.         lsIOFF
  4654.  
  4655.         Declarations:
  4656.              procedure lsIoff;
  4657.  
  4658.         Purpose:
  4659.              Turns I/O checking off during execution of lsReadLn and
  4660.         lsWriteLn.
  4661.  
  4662.         Examples:
  4663.                   lsIoff;
  4664.                   lsReadLn(MyFile, MyLS);
  4665.                   if lsIoResult <> 0 then {Do something}
  4666.                   lsIon;
  4667.  
  4668.         Comments:
  4669.              lsIoff, lsIon, and lsIoResult MUST be used for LongString
  4670.         I/O operations in place of $I-, $I+, and IoResult.
  4671.  
  4672.              Emulates at execution time the action of the $I- compiler
  4673.         directive, but only for LongString I/O. The default state is
  4674.         "on".
  4675.  
  4676.              If I/O checking is off lsIoResult MUST be called after each
  4677.         call to lsReadLn or lsWriteLn. If I/O checking is on, and if an
  4678.         I/O error occurs, the program will terminate with a run-time
  4679.         error. This action duplicates the action of the IoResult function
  4680.         for normal I/O.
  4681.  
  4682.         See Also:
  4683.              lsIon     lsIoResult
  4684.  
  4685.  
  4686.  
  4687.  
  4688.  
  4689.  
  4690.  
  4691.  
  4692.  
  4693.  
  4694.  
  4695.  
  4696.  
  4697.  
  4698.  
  4699.  
  4700.  
  4701.  
  4702.  
  4703.  
  4704.  
  4705.  
  4706.                                   ShLngStr  8-15
  4707.  
  4708.  
  4709.  
  4710.         ____________________________
  4711.         lsION
  4712.  
  4713.         Declarations:
  4714.              procedure lsIon;
  4715.  
  4716.         Purpose:
  4717.              Turns I/O checking on during execution of lsReadLn and
  4718.         lsWriteLn.
  4719.  
  4720.         Examples:
  4721.                   lsIoff;
  4722.                   lsReadLn(MyFile, MyLS);
  4723.                   if lsIoResult <> 0 then {Do something}
  4724.                   lsIon;
  4725.  
  4726.         Comments:
  4727.              lsIoff, lsIon, and lsIoResult MUST be used for LongString
  4728.         I/O operations in place of $I-, $I+, and IoResult.
  4729.  
  4730.              Emulates at execution time the action of the $I+ compiler
  4731.         directive, but only for LongString I/O. The default state is
  4732.         "on".
  4733.  
  4734.              If I/O checking is off lsIoResult MUST be called after each
  4735.         call to lsReadLn or lsWriteLn. If I/O checking is on, and if an
  4736.         I/O error occurs, the program will terminate with a run-time
  4737.         error. This action duplicates the action of the IoResult function
  4738.         for normal I/O.
  4739.  
  4740.         See Also:
  4741.              lsIoff    lsIoResult
  4742.  
  4743.  
  4744.  
  4745.  
  4746.  
  4747.  
  4748.  
  4749.  
  4750.  
  4751.  
  4752.  
  4753.  
  4754.  
  4755.  
  4756.  
  4757.  
  4758.  
  4759.  
  4760.  
  4761.  
  4762.  
  4763.  
  4764.                                   ShLngStr  8-16
  4765.  
  4766.  
  4767.  
  4768.         ____________________________
  4769.         lsIORESULT
  4770.  
  4771.         Declarations:
  4772.              function lsIoResult: word;
  4773.  
  4774.         Purpose:
  4775.              Returns the IoResult of the last lsReadLn or lsWriteLn
  4776.         performed, and clears the internal variable used to store the
  4777.         value.
  4778.  
  4779.         Examples:
  4780.                   lsIoff;
  4781.                   lsReadLn(MyFile, MyLS);
  4782.                   if lsIoResult <> 0 then {Do something}
  4783.                   lsIon;
  4784.  
  4785.         Comments:
  4786.              lsIoff, lsIon, and lsIoResult MUST be used for LongString
  4787.         I/O operations in place of $I-, $I+, and IoResult.
  4788.  
  4789.              If I/O checking is off lsIoResult MUST be called after each
  4790.         call to lsReadLn or lsWriteLn. If I/O checking is on, and if an
  4791.         I/O error occurs, the program will terminate with a run-time
  4792.         error. This action duplicates the action of the IoResult function
  4793.         for normal I/O.
  4794.  
  4795.         See Also:
  4796.              lsIoff    lsIon
  4797.  
  4798.  
  4799.  
  4800.  
  4801.  
  4802.  
  4803.  
  4804.  
  4805.  
  4806.  
  4807.  
  4808.  
  4809.  
  4810.  
  4811.  
  4812.  
  4813.  
  4814.  
  4815.  
  4816.  
  4817.  
  4818.  
  4819.  
  4820.  
  4821.  
  4822.                                   ShLngStr  8-17
  4823.  
  4824.  
  4825.  
  4826.         ____________________________
  4827.         lsINSERT
  4828.  
  4829.         Declarations:
  4830.              procedure lsInsert
  4831.                   (A, Obj: LongString; Start: word; B: LongString);
  4832.              function lsInsertF
  4833.                   (A, Obj: LongString; Start: word): LongString;
  4834.              procedure lsInsertStr
  4835.                   (A: LongString; Obj: string; Start: word;
  4836.                                                           B: LongString);
  4837.              function lsInsertStrF
  4838.                   (A: LongString; Obj: string; Start: word): LongString;
  4839.  
  4840.         Purpose:
  4841.              Insert Obj into A at position Start returning a new
  4842.         LongString.
  4843.  
  4844.         Examples:
  4845.              If             A contains "abcdef"
  4846.              and            Obj contains "ABC"
  4847.              then           lsInsert(A, Obj, 4, B);
  4848.              results in     B containing "abcABCdef"
  4849.  
  4850.         Comments:
  4851.              If Start > lsLength(A), no action is taken.
  4852.  
  4853.         See Also:
  4854.              lsDelete
  4855.  
  4856.  
  4857.  
  4858.  
  4859.  
  4860.  
  4861.  
  4862.  
  4863.  
  4864.  
  4865.  
  4866.  
  4867.  
  4868.  
  4869.  
  4870.  
  4871.  
  4872.  
  4873.  
  4874.  
  4875.  
  4876.  
  4877.  
  4878.  
  4879.  
  4880.                                   ShLngStr  8-18
  4881.  
  4882.  
  4883.  
  4884.         ____________________________
  4885.         lsLEFTPAD
  4886.  
  4887.         Declarations:
  4888.              procedure lsLeftPad
  4889.                   (A: LongString; Len: word; B: LongString);
  4890.              function lsLeftPadF
  4891.                   (A: LongString; Len: word): LongString;
  4892.  
  4893.         Purpose:
  4894.              Left-pad the LongString in A to length Len with blanks,
  4895.         returning a new LongString.
  4896.  
  4897.         Examples:
  4898.              If             A contains "abc"
  4899.              then           lsLeftPad(A, 5, B);
  4900.              results in     B containing "  abc"
  4901.  
  4902.         Comments:
  4903.              If Len < lsLength(A), A is returned truncated without
  4904.         padding.
  4905.  
  4906.         See Also:
  4907.              lsLeftPadCh     lsPad           lsPadCh
  4908.  
  4909.  
  4910.         ____________________________
  4911.         lsLEFTPADCH
  4912.  
  4913.         Declarations:
  4914.              procedure lsLeftPadCh
  4915.                   (A: LongString; Ch: Char; Len: word; B: LongString);
  4916.              function lsLeftPadChF
  4917.                   (A: LongString; Ch: Char; Len: word): LongString;
  4918.  
  4919.         Purpose:
  4920.              Left-pad the LongString in A to length Len with Ch,
  4921.         returning a new LongString.
  4922.  
  4923.         Examples:
  4924.              If             A contains "abc"
  4925.              then           lsLeftPad(A, '+', 5, B);
  4926.              results in     B containing "++abc"
  4927.  
  4928.         Comments:
  4929.  
  4930.         See Also:
  4931.              lsLeftPad       lsPad           lsPadCh
  4932.  
  4933.  
  4934.  
  4935.  
  4936.  
  4937.  
  4938.                                   ShLngStr  8-19
  4939.  
  4940.  
  4941.  
  4942.         ____________________________
  4943.         lsLENGTH
  4944.  
  4945.         Declarations:
  4946.              function lsLength
  4947.                   (A: LongString): word;
  4948.  
  4949.         Purpose:
  4950.              Return the length of a LongString. A must have been
  4951.         initialized.
  4952.  
  4953.         Examples:
  4954.              If             A contains "Cogito, ergo sum."
  4955.              then           lsLength(A)
  4956.              returns        17
  4957.  
  4958.         Comments:
  4959.  
  4960.         See Also:
  4961.  
  4962.  
  4963.         ____________________________
  4964.         lsLOCASE
  4965.  
  4966.         Declarations:
  4967.              procedure lsLocase
  4968.                   (A, B: LongString);
  4969.              function lsLocaseF
  4970.                   (A: LongString): LongString;
  4971.  
  4972.         Purpose:
  4973.              Locase the LongString in A, returning a new LongString.
  4974.  
  4975.         Examples:
  4976.              If             A contains "ABCdefGHIjkl"
  4977.              then           lsLocase(A, B);
  4978.              results in     B containing "abcdefghijkl"
  4979.  
  4980.         Comments:
  4981.  
  4982.         See Also:
  4983.              lsUpcase
  4984.  
  4985.  
  4986.  
  4987.  
  4988.  
  4989.  
  4990.  
  4991.  
  4992.  
  4993.  
  4994.  
  4995.  
  4996.                                   ShLngStr  8-20
  4997.  
  4998.  
  4999.  
  5000.         ____________________________
  5001.         lsLONGSTRING2STR
  5002.  
  5003.         Declarations:
  5004.              function lsLongString2Str
  5005.                   (A: LongString): string;
  5006.  
  5007.         Purpose:
  5008.              Convert a LongString to a Turbo string.
  5009.  
  5010.         Examples:
  5011.              If             A (LongString) contains "abcdef"
  5012.              then           lsLongString2Str(A)
  5013.              returns        'abcdef' (string)
  5014.  
  5015.         Comments:
  5016.              If lsLength(A) > 255, the returned string will be truncated
  5017.         to length 255.
  5018.  
  5019.         See Also:
  5020.              lsStr2LongString
  5021.  
  5022.  
  5023.         ____________________________
  5024.         lsPAD
  5025.  
  5026.         Declarations:
  5027.              procedure lsPad
  5028.                   (A: LongString; Len: word; B: LongString);
  5029.              function lsPadF
  5030.                   (A: LongString; Len: word): LongString;
  5031.  
  5032.         Purpose:
  5033.              Right-pad the LongString in A to length Len with blanks,
  5034.         returning a new LongString.
  5035.  
  5036.         Examples:
  5037.              If             A contains "abc"
  5038.              then           lsPad(A, 5, B);
  5039.              results in     B containing "abc  "
  5040.  
  5041.              but if         lsInit(C, 5) = true
  5042.              then           lsPad(A, 8, C);
  5043.              also results in  C containing "abc  "
  5044.  
  5045.         Comments:
  5046.  
  5047.         See Also:
  5048.              lsPadCh         lsLeftPad       lsLeftPadCh
  5049.  
  5050.  
  5051.  
  5052.  
  5053.  
  5054.                                   ShLngStr  8-21
  5055.  
  5056.  
  5057.  
  5058.         ____________________________
  5059.         lsPADCH
  5060.  
  5061.         Declarations:
  5062.              procedure lsPadCh
  5063.                   (A: LongString; Ch: Char; Len: word; B: LongString);
  5064.              function lsPadChF
  5065.                   (A: LongString; Ch: Char; Len: word): LongString;
  5066.  
  5067.         Purpose:
  5068.              Right-pad the LongString in A to length Len with Ch,
  5069.         returning a new LongString.
  5070.  
  5071.         Examples:
  5072.              If             A contains "abc"
  5073.              then           lsPadCh(A, '+', 5, B);
  5074.              results in     B containing "abc++"
  5075.  
  5076.              but if         lsInit(C, 5) = true
  5077.              then           lsPadCh(A, '+', 8, C);
  5078.              also results in  C containing "abc++"
  5079.  
  5080.         Comments:
  5081.  
  5082.         See Also:
  5083.              lsPad           lsLeftPad       lsLeftPadCh
  5084.  
  5085.  
  5086.  
  5087.  
  5088.  
  5089.  
  5090.  
  5091.  
  5092.  
  5093.  
  5094.  
  5095.  
  5096.  
  5097.  
  5098.  
  5099.  
  5100.  
  5101.  
  5102.  
  5103.  
  5104.  
  5105.  
  5106.  
  5107.  
  5108.  
  5109.  
  5110.  
  5111.  
  5112.                                   ShLngStr  8-22
  5113.  
  5114.  
  5115.  
  5116.         ____________________________
  5117.         lsPOS
  5118.  
  5119.         Declarations:
  5120.              function lsPos
  5121.                   (Obj, A: LongString): word;
  5122.              function lsPosStr
  5123.                   (Obj: string; A: LongString): word;
  5124.              function lsPosUC
  5125.                   (Obj, A: LongString): word;
  5126.              function lsPosStrUC
  5127.                   (Obj: string; A: LongString): word;
  5128.  
  5129.         Purpose:
  5130.              Return the position of Obj in A, returning NotFound if not
  5131.         found.
  5132.  
  5133.         Examples:
  5134.              If             A contains "abcdeabcdeabcde"
  5135.              and            Obj contains "BCD"
  5136.              then           lsPos(A, Obj)
  5137.              returns        NotFound ( = 0 )
  5138.              but            lsPosUC(A, Obj)
  5139.              returns        2
  5140.  
  5141.         Comments:
  5142.  
  5143.         See Also:
  5144.  
  5145.  
  5146.         ____________________________
  5147.         lsPOSSET
  5148.  
  5149.         Declaration:
  5150.              function lsPosSet(A : CharSet; S : LongString) : byte;
  5151.  
  5152.         Purpose:
  5153.              Returns the position of the first occurrence of any member
  5154.         of A in S.
  5155.  
  5156.         Comments:
  5157.              This function is primarily intended for internal use.
  5158.  
  5159.         Examples:
  5160.                   If   S = 'X1Y2C3Z4B'
  5161.                   and  A = ['A','B','C']
  5162.                   then lsPosSet(A, S) will return 5.
  5163.  
  5164.         See also:
  5165.  
  5166.  
  5167.  
  5168.  
  5169.  
  5170.                                   ShLngStr  8-23
  5171.  
  5172.  
  5173.  
  5174.         ____________________________
  5175.         lsREADLN
  5176.  
  5177.         Declarations:
  5178.              procedure lsReadLn
  5179.                   (var F: Text; A: LongString);
  5180.  
  5181.         Purpose:
  5182.              Read a LongString from a text file.
  5183.  
  5184.         Examples:
  5185.              lsReadLn(MyFile, A);
  5186.  
  5187.         Comments:
  5188.              If the "declared" length of A (set by lsInit) is less than
  5189.         the actual length of the line in the text file, the incoming
  5190.         string will be truncated to the "declared" length of A and the
  5191.         file will be positioned at the beginning of the next line (the
  5192.         exact analog of a normal Turbo PASCAL string ReadLn).
  5193.  
  5194.              If I/O checking is off lsIoResult MUST be called after each
  5195.         call to lsReadLn or lsWriteLn. If I/O checking is on, and if an
  5196.         I/O error occurs, the program will terminate with a run-time
  5197.         error. This action duplicates the action of the IoResult function
  5198.         for normal I/O.
  5199.  
  5200.         See Also:
  5201.              lsIoff    lsIon     lsIoResult     lsWriteLn
  5202.  
  5203.  
  5204.  
  5205.  
  5206.  
  5207.  
  5208.  
  5209.  
  5210.  
  5211.  
  5212.  
  5213.  
  5214.  
  5215.  
  5216.  
  5217.  
  5218.  
  5219.  
  5220.  
  5221.  
  5222.  
  5223.  
  5224.  
  5225.  
  5226.  
  5227.  
  5228.                                   ShLngStr  8-24
  5229.  
  5230.  
  5231.  
  5232.         ____________________________
  5233.         lsREPALL
  5234.  
  5235.         Declarations:
  5236.              procedure lsRepAll
  5237.                   (A, Obj, Obj1, B: LongString);
  5238.              function lsRepAllF
  5239.                   (A, Obj, Obj1: LongString):  LongString;
  5240.              procedure lsRepAllStr
  5241.                   (A: LongString; Obj, Obj1: string; B: LongString);
  5242.              function lsRepAllStrF
  5243.                   (A: LongString; Obj, Obj1: string): LongString;
  5244.              procedure lsRepAllStrUC
  5245.                   (A: LongString; Obj, Obj1: string; B: LongString);
  5246.              function lsRepAllStrUCF
  5247.                   (A: LongString; Obj, Obj1: string): LongString;
  5248.              procedure lsRepAllUC
  5249.                   (A, Obj, Obj1, B: LongString);
  5250.              function lsRepAllUCF
  5251.                   (A, Obj, Obj1: LongString): LongString;
  5252.  
  5253.         Purpose:
  5254.              Replaces all occurrences of Obj in A with Obj1.
  5255.  
  5256.         Examples:
  5257.              If             A contains 'aabcbcabcd'
  5258.              and            Obj contains 'abc'
  5259.              and            Obj1 contains '12345'
  5260.              then           lsRepAll(A, Obj, Obj1, B);
  5261.              results in     B containing 'a12345bc12345d'
  5262.  
  5263.         Comments:
  5264.              Should the replacement of Obj by Obj1 in A result in a new
  5265.         occurrence of Obj in A, the new occurrence will not be replaced.
  5266.         To do so, except under rather unusual conditions, could result in
  5267.         a non-terminating condition.
  5268.  
  5269.         See Also:
  5270.              lsDelAll
  5271.  
  5272.  
  5273.  
  5274.  
  5275.  
  5276.  
  5277.  
  5278.  
  5279.  
  5280.  
  5281.  
  5282.  
  5283.  
  5284.  
  5285.  
  5286.                                   ShLngStr  8-25
  5287.  
  5288.  
  5289.  
  5290.         ____________________________
  5291.         lsSIZEOF
  5292.  
  5293.         Declarations:
  5294.              function lsSizeOf
  5295.                   (A: LongString): word;
  5296.  
  5297.         Purpose:
  5298.              Returns the total heap space required for A, including the
  5299.         two control words. A must have been initialized.
  5300.  
  5301.         Examples:
  5302.              See below.
  5303.  
  5304.         Comments:
  5305.              lsSizeOf MUST be used to determine the effective size of a
  5306.         LongString. Any attempt to use SizeOf(A) will return a value of
  5307.         4; any attempt to use SizeOf(A^) will return a value of 5.
  5308.         Neither is particularly informative!
  5309.  
  5310.              Remember that, just as
  5311.                               SizeOf(StringVariable)
  5312.         returns a value one greater than the declared length of
  5313.         StringVariable, so
  5314.                            lsSizeOf(LongStringVariable)
  5315.         will return a value four greater than the "declared" length of
  5316.         LongStringVariable.
  5317.  
  5318.              If A has not been initialized, the results are
  5319.         unpredictable.
  5320.  
  5321.         See Also:
  5322.              lsLength
  5323.  
  5324.  
  5325.  
  5326.  
  5327.  
  5328.  
  5329.  
  5330.  
  5331.  
  5332.  
  5333.  
  5334.  
  5335.  
  5336.  
  5337.  
  5338.  
  5339.  
  5340.  
  5341.  
  5342.  
  5343.  
  5344.                                   ShLngStr  8-26
  5345.  
  5346.  
  5347.  
  5348.         ____________________________
  5349.         lsSTR2LONGSTRING
  5350.  
  5351.         Declarations:
  5352.              procedure lsStr2LongString
  5353.                   (S: string; A: LongString);
  5354.              function lsStr2LongStringF
  5355.                   (S: string): LongString;
  5356.  
  5357.         Purpose:
  5358.              Convert a Turbo string into a LongString.
  5359.  
  5360.         Examples:
  5361.              If             S (string) contains "abcdef"
  5362.              then           lsStr2LongString(S, A);
  5363.              results in     A (LongString) containing "abcdef"
  5364.  
  5365.         Comments:
  5366.  
  5367.         See Also:
  5368.              lsLongString2Str
  5369.  
  5370.  
  5371.         ____________________________
  5372.         lsTRANSFER
  5373.  
  5374.         Declarations:
  5375.              procedure lsTransfer
  5376.                   (A, B: LongString);
  5377.  
  5378.         Purpose:
  5379.              Transfers the contents of A into B.
  5380.  
  5381.         Examples:
  5382.              B^ := A^;
  5383.              INCORRECT!! This construct will give unpredictable but guar-
  5384.         anteed incorrect results.
  5385.  
  5386.              lsTransfer(A, B);
  5387.              Correct. ALWAYS use lsTransfer to move the contents of one
  5388.         LongString into another.
  5389.  
  5390.         Comments:
  5391.  
  5392.         See Also:
  5393.  
  5394.  
  5395.  
  5396.  
  5397.  
  5398.  
  5399.  
  5400.  
  5401.  
  5402.                                   ShLngStr  8-27
  5403.  
  5404.  
  5405.  
  5406.         ____________________________
  5407.         lsTRIM
  5408.  
  5409.         Declarations:
  5410.              procedure lsTrim
  5411.                   (A, B: LongString);
  5412.              function lsTrimF
  5413.                   (A: LongString): LongString;
  5414.  
  5415.         Purpose:
  5416.              Return a LongString with leading and trailing white space
  5417.         removed.
  5418.  
  5419.         Examples:
  5420.              If             A contains "  Cogito, ergo sum.      "
  5421.              then           lsTrim(A, B);
  5422.              results in     B containing "Cogito, ergo sum."
  5423.  
  5424.         Comments:
  5425.              "White space" is any sequence of characters in the range
  5426.         #0..#32.
  5427.  
  5428.         See Also:
  5429.              lsTrimLead     lsTrimTrail
  5430.              lsTrimLeadSet  lsTrimSet      lsTrimTrailSet
  5431.  
  5432.  
  5433.         ____________________________
  5434.         lsTRIMLEAD
  5435.  
  5436.         Declarations:
  5437.              procedure lsTrimLead
  5438.                   (A, B: LongString);
  5439.              function lsTrimLeadF
  5440.                   (A: LongString): LongString;
  5441.  
  5442.         Purpose:
  5443.              Return a LongString with leading white space removed.
  5444.  
  5445.         Examples:
  5446.              If             A contains "  Cogito, ergo sum.      "
  5447.              then           lsTrimLead(A, B);
  5448.              results in     B containing "Cogito, ergo sum.      "
  5449.  
  5450.         Comments:
  5451.              "White space" is any sequence of characters in the range
  5452.         #0..#32.
  5453.  
  5454.         See Also:
  5455.              lsTrim         lsTrimTrail
  5456.              lsTrimLeadSet  lsTrimSet      lsTrimTrailSet
  5457.  
  5458.  
  5459.  
  5460.                                   ShLngStr  8-28
  5461.  
  5462.  
  5463.  
  5464.         ____________________________
  5465.         lsTRIMTRAIL
  5466.  
  5467.         Declarations:
  5468.              procedure lsTrimTrail
  5469.                   (A, B: LongString);
  5470.              function lsTrimTrailF
  5471.                   (A: LongString): LongString;
  5472.  
  5473.         Purpose:
  5474.           Return a LongString with trailing white space removed.
  5475.  
  5476.         Examples:
  5477.              If             A contains "  Cogito, ergo sum.      "
  5478.              then           lsTrimTrail(A, B);
  5479.              results in     B containing "  Cogito, ergo sum."
  5480.  
  5481.         Comments:
  5482.              "White space" is any sequence of characters in the range
  5483.         #0..#32.
  5484.  
  5485.         See Also:
  5486.              lsTrim         lsTrimLead
  5487.              lsTrimLeadSet  lsTrimSet      lsTrimTrailSet
  5488.  
  5489.  
  5490.         ____________________________
  5491.         lsTRIMLEADSET
  5492.         Declaration:
  5493.              procedure lsTrimLeadSet
  5494.                   (A : LongString; CS : CharSet; B : LongString);
  5495.              function lsTrimLeadSetF
  5496.                   (A : LongString; CS : CharSet) : LongString;
  5497.  
  5498.         Purpose:
  5499.              Returns a LongString with leading characters in CS stripped.
  5500.  
  5501.         Examples:
  5502.              See the file TESTLSTR.PAS
  5503.  
  5504.         Comments:
  5505.              CS contains an arbitrary set of characters.
  5506.  
  5507.         See also:
  5508.              lsTrimSet lsTrimTrailSet
  5509.              lsTrim    lsTrimLead     lsTrimTrail
  5510.  
  5511.  
  5512.  
  5513.  
  5514.  
  5515.  
  5516.  
  5517.  
  5518.                                   ShLngStr  8-29
  5519.  
  5520.  
  5521.  
  5522.         ____________________________
  5523.         lsTRIMSET
  5524.  
  5525.         Declaration:
  5526.              procedure lsTrimSet
  5527.                   (A : LongString; CS : CharSet; B : LongString);
  5528.              function lsTrimSetF
  5529.                   (A  : LongString; CS : CharSet) : LongString;
  5530.  
  5531.         Purpose:
  5532.              Returns a LongString with leading and trailing characters in
  5533.         CS stripped.
  5534.  
  5535.         Examples:
  5536.              See the file TESTLSTR.PAS
  5537.  
  5538.         Comments:
  5539.              CS contains an arbitrary set of characters.
  5540.  
  5541.         See also:
  5542.              lsTrimLeadSet  lsTrimTrailSet
  5543.              lsTrim         lsTrimLead     lsTrimTrail
  5544.  
  5545.  
  5546.         ____________________________
  5547.         lsTRIMTRAILSET
  5548.  
  5549.         Declaration:
  5550.              procedure lsTrimTrailSet
  5551.                   (A : LongString; CS : CharSet; B : LongString);
  5552.              function lsTrimTrailSetF
  5553.                   (A : LongString; CS : CharSet) : LongString;
  5554.  
  5555.         Purpose:
  5556.              Returns a LongString with trailing characters in CS
  5557.         stripped.
  5558.  
  5559.         Examples:
  5560.              See the file TESTLSTR.PAS
  5561.  
  5562.         Comments:
  5563.              CS contains an arbitrary set of characters.
  5564.  
  5565.         See also:
  5566.              lsTrimLeadSet  lsTrimSet
  5567.              lsTrim         lsTrimLead     lsTrimTrail
  5568.  
  5569.  
  5570.  
  5571.  
  5572.  
  5573.  
  5574.  
  5575.  
  5576.                                   ShLngStr  8-30
  5577.  
  5578.  
  5579.  
  5580.         ____________________________
  5581.         lsUPCASE
  5582.  
  5583.         Declarations:
  5584.              procedure lsUpcase
  5585.                   (A, B: LongString);
  5586.              function lsUpcaseF
  5587.                   (A: LongString): LongString;
  5588.  
  5589.         Purpose:
  5590.              Upcase the LongString in A, returning a new LongString.
  5591.  
  5592.         Examples:
  5593.              If             A contains "ABCdefGHIjkl"
  5594.              then           lsUpcase(A, B);
  5595.              results in     B containing "ABCDEFGHIJKL"
  5596.  
  5597.         Comments:
  5598.  
  5599.         See Also:
  5600.              lsLocase
  5601.  
  5602.  
  5603.         ____________________________
  5604.         lsWRITELN
  5605.  
  5606.         Declarations:
  5607.              procedure lsWriteLn
  5608.                   (var F: Text; A: LongString);
  5609.  
  5610.         Purpose:
  5611.              Write a LongString to a text file.
  5612.  
  5613.         Examples:
  5614.              lsWriteLn(MyFile, A);
  5615.  
  5616.         Comments:
  5617.              If I/O checking is off lsIoResult MUST be called after each
  5618.         call to lsReadLn or lsWriteLn. If I/O checking is on, and if an
  5619.         I/O error occurs, the program will terminate with a run-time
  5620.         error. This action duplicates the action of the IoResult function
  5621.         for normal I/O.
  5622.  
  5623.         See Also:
  5624.              lsIoff    lsIon     lsIoResult     lsReadLn
  5625.  
  5626.  
  5627.  
  5628.  
  5629.  
  5630.  
  5631.  
  5632.  
  5633.  
  5634.                                   ShLngStr  8-31
  5635.                                                          03/25/92 01:54pm
  5636.  
  5637.  
  5638.  
  5639.  
  5640.  
  5641.  
  5642.  
  5643.  
  5644.  
  5645.  
  5646.  
  5647.  
  5648.  
  5649.  
  5650.  
  5651.  
  5652.  
  5653.  
  5654.  
  5655.  
  5656.  
  5657.                        This page has been deliberately left
  5658.                          blank, except for this message.
  5659.  
  5660.  
  5661.  
  5662.  
  5663.  
  5664.  
  5665.  
  5666.  
  5667.  
  5668.  
  5669.  
  5670.  
  5671.  
  5672.  
  5673.  
  5674.  
  5675.  
  5676.  
  5677.  
  5678.  
  5679.  
  5680.  
  5681.  
  5682.  
  5683.  
  5684.  
  5685.  
  5686.  
  5687.  
  5688.  
  5689.  
  5690.  
  5691.  
  5692.  
  5693.                                   ShLngStr  8-32
  5694.  
  5695.  
  5696.  
  5697.  
  5698.  
  5699.  
  5700.                                     ShUtilPk
  5701.  
  5702.                                   A Utility Unit
  5703.  
  5704.  
  5705.         INTRODUCTION
  5706.              ShUtilPk provides a number of miscellaneous utility routines
  5707.         which do not fit naturally into any of the other units of the
  5708.         SkyHawk collection.
  5709.  
  5710.  
  5711.         INTERFACED ELEMENTS
  5712.  
  5713.         Types
  5714.         =====
  5715.              DelimSetType = Set of Char;
  5716.  
  5717.         Constants
  5718.         =========
  5719.              DelimSet : DelimSetType = [#0..#32];
  5720.              The typed constant used by the GetNext routines to determine
  5721.         the end of a substring to be returned. It may be freely changed
  5722.         during program execution.
  5723.  
  5724.         Variables
  5725.         =========
  5726.              Two variables are interfaced, containing the video mode and
  5727.         video attribute of the system at the time the containing program
  5728.         was invoked. NEVER MODIFY THESE VARIABLES!
  5729.  
  5730.              StartingMode : Integer;
  5731.              {Initial video mode of the system (Mono, CO80, BW40, ...)}
  5732.  
  5733.              StartingAttr : Byte;
  5734.              {Initial video attribute of the system}
  5735.  
  5736.  
  5737.  
  5738.  
  5739.  
  5740.  
  5741.  
  5742.  
  5743.  
  5744.  
  5745.  
  5746.  
  5747.  
  5748.  
  5749.  
  5750.  
  5751.                                   ShUtilPk  9-1
  5752.  
  5753.  
  5754.  
  5755.         Routines
  5756.         ========
  5757.         ____________________________
  5758.         BETWS
  5759.  
  5760.         Declaration:
  5761.              function BetwS(Lower, Item, Upper  : LongInt) : boolean;
  5762.  
  5763.         Purpose:
  5764.              Performs a SIGNED test of the condition that
  5765.  
  5766.                               Lower <= Item <= Upper
  5767.  
  5768.         returning TRUE if and only if the condition is met.
  5769.  
  5770.         Comments:
  5771.              Lower, Item, and Upper can be any combination of 1, 2, and
  5772.         4-byte entities.
  5773.  
  5774.              Note that
  5775.                   BetwU($EA, $EA, $FA) = true
  5776.              whereas
  5777.                   BetwS($EA, $EA, $FA) = false
  5778.  
  5779.         Examples:
  5780.              See TESTBETW.PAS
  5781.  
  5782.         See also:
  5783.              BetwU
  5784.  
  5785.  
  5786.  
  5787.  
  5788.  
  5789.  
  5790.  
  5791.  
  5792.  
  5793.  
  5794.  
  5795.  
  5796.  
  5797.  
  5798.  
  5799.  
  5800.  
  5801.  
  5802.  
  5803.  
  5804.  
  5805.  
  5806.  
  5807.  
  5808.  
  5809.                                   ShUtilPk  9-2
  5810.  
  5811.  
  5812.  
  5813.         ____________________________
  5814.         BETWU
  5815.  
  5816.         Declaration:
  5817.              function BetwU(Lower, Item, Upper  : LongInt) : boolean;
  5818.  
  5819.         Purpose:
  5820.              Performs an UNSIGNED test of the condition that
  5821.  
  5822.                               Lower <= Item <= Upper
  5823.  
  5824.         returning TRUE if and only if the condition is met.
  5825.  
  5826.         Comments:
  5827.              Lower, Item, and Upper can be any combination of 1, 2, and
  5828.         4-byte entities.
  5829.  
  5830.              Note that
  5831.                   BetwU($EA, $EA, $FA) = true
  5832.              whereas
  5833.                   BetwS($EA, $EA, $FA) = false
  5834.  
  5835.         Examples:
  5836.              See TESTBETW.PAS
  5837.  
  5838.         See also:
  5839.              BetwS
  5840.  
  5841.  
  5842.         ____________________________
  5843.         DELALL
  5844.  
  5845.         Declaration:
  5846.              procedure DelAll(S1, DS : String; S2);
  5847.              function DelAllF(S1, DS : string) : string;
  5848.  
  5849.         Purpose:
  5850.              In string S1 delete all occurrences of DS.
  5851.  
  5852.         Comments:
  5853.  
  5854.         Examples:
  5855.              See the file TESTUTIL.PAS
  5856.  
  5857.         See also:
  5858.              RepAll
  5859.  
  5860.  
  5861.  
  5862.  
  5863.  
  5864.  
  5865.  
  5866.  
  5867.                                   ShUtilPk  9-3
  5868.  
  5869.  
  5870.  
  5871.         ____________________________
  5872.         GETNEXT
  5873.  
  5874.         Declaration:
  5875.              procedure GetNext(var S1, S2 : String);
  5876.              function GetNextF(var S1 : String) : String;
  5877.  
  5878.         Purpose:
  5879.              Returns the next leading substring of S1 which is delimited
  5880.         by a member of DelimSet.
  5881.  
  5882.         Comments:
  5883.              S1 is returned with the sub-string stripped off, but not
  5884.         trimmed. S2 or the function value is trimmed.
  5885.  
  5886.              If S1 is empty on entry, both S1 and S2 (or the function
  5887.         value) will be empty on return.
  5888.  
  5889.         Examples:
  5890.              See the file TESTUTIL.PAS
  5891.  
  5892.         See also:
  5893.  
  5894.  
  5895.  
  5896.  
  5897.  
  5898.  
  5899.  
  5900.  
  5901.  
  5902.  
  5903.  
  5904.  
  5905.  
  5906.  
  5907.  
  5908.  
  5909.  
  5910.  
  5911.  
  5912.  
  5913.  
  5914.  
  5915.  
  5916.  
  5917.  
  5918.  
  5919.  
  5920.  
  5921.  
  5922.  
  5923.  
  5924.  
  5925.                                   ShUtilPk  9-4
  5926.  
  5927.  
  5928.  
  5929.         ____________________________
  5930.         HEX
  5931.  
  5932.         Declaration:
  5933.              function HEX(A : LongInt) : String;
  5934.  
  5935.         Purpose:
  5936.              Converts any INTEGER-type variable into a string
  5937.         correspnoding to the hex value.
  5938.  
  5939.         Comments:
  5940.              The parameter A may be of any Integer type (ShortInt, Byte,
  5941.         Integer, Word, or LongInt
  5942.  
  5943.              HEX will return either a 2, 4, or 8 character string,
  5944.         depending on whether the actual value of the parameter (rather
  5945.         than its type) is representable by a
  5946.  
  5947.                             1 byte value (ShortInt, Byte)
  5948.                             2 byte value (Integer, Word)
  5949.                             4 byte value (LongInt)
  5950.  
  5951.              Note that a negative value will always be returned as an 8
  5952.         character string.
  5953.  
  5954.         Examples:
  5955.              See the file TESTUTIL.PAS
  5956.  
  5957.         See also:
  5958.  
  5959.  
  5960.         ____________________________
  5961.         HIWORD
  5962.  
  5963.         Declaration:
  5964.              function HiWord(LI : LongInt) : Word;
  5965.  
  5966.         Purpose:
  5967.              Returns the high order word of a LongInt.
  5968.  
  5969.         Comments:
  5970.              This function is the analog of the system function HI, per-
  5971.         forming the analogous operation on a LongInt to that performed by
  5972.         HI on an INTEGER or WORD.
  5973.  
  5974.         Examples:
  5975.              See the file TESTUTIL.PAS
  5976.  
  5977.         See also:
  5978.              LoWord
  5979.  
  5980.  
  5981.  
  5982.  
  5983.                                   ShUtilPk  9-5
  5984.  
  5985.  
  5986.  
  5987.         ____________________________
  5988.         LI
  5989.  
  5990.         Declaration:
  5991.              function LI(Ilo, Ihi : Word) : LongInt;
  5992.  
  5993.         Purpose:
  5994.              Converts two Word variables to a LongInt
  5995.  
  5996.         Comments:
  5997.  
  5998.         Examples:
  5999.              See the file TESTUTIL.PAS
  6000.  
  6001.         See also:
  6002.  
  6003.  
  6004.         ____________________________
  6005.         LOWORD
  6006.  
  6007.         Declaration:
  6008.              function LoWord(LI : LongInt) : Word;
  6009.  
  6010.         Purpose:
  6011.              Returns the low order word of a LongInt.
  6012.  
  6013.         Comments:
  6014.              This function is the analog of the system function LO, per-
  6015.         forming the analogous operation on a LongInt to that performed by
  6016.         LO on an INTEGER or WORD.
  6017.  
  6018.         Examples:
  6019.              See the file TESTUTIL.PAS
  6020.  
  6021.         See also:
  6022.              HiWord
  6023.  
  6024.  
  6025.  
  6026.  
  6027.  
  6028.  
  6029.  
  6030.  
  6031.  
  6032.  
  6033.  
  6034.  
  6035.  
  6036.  
  6037.  
  6038.  
  6039.  
  6040.  
  6041.                                   ShUtilPk  9-6
  6042.  
  6043.  
  6044.  
  6045.         ____________________________
  6046.         PMOD
  6047.  
  6048.         Declaration:
  6049.              function Pmod(X, Modulus : LongInt) : LongInt;
  6050.  
  6051.         Purpose:
  6052.              Returns the remainder of X on division by MODULUS as a
  6053.         positive number, regardless of the sign of X.
  6054.  
  6055.         Comments:
  6056.              Recall that, e.g., -1 is congruent to (modulus-1). Thus, for
  6057.         example, Pmod(-2, 7) will return 5 as the function value.
  6058.  
  6059.         Examples:
  6060.              (-2 mod 5) = -2
  6061.              Pmod(-2, 5) = 3
  6062.              See the file TESTUTIL.PAS
  6063.  
  6064.         See also:
  6065.  
  6066.  
  6067.         ____________________________
  6068.         POSSET
  6069.  
  6070.         Declaration:
  6071.              function PosSet(A : CharSet; S : string) : byte;
  6072.  
  6073.         Purpose:
  6074.              Returns the position of the first occurrence of any member
  6075.         of A in S.
  6076.  
  6077.         Comments:
  6078.              This function is intended primarily for internal use by
  6079.         ShUtilPk and ShCmdLin.
  6080.  
  6081.         Examples:
  6082.                   If   S = 'X1Y2C3Z4B'
  6083.                   and  A = ['A','B','C']
  6084.                   then PosSet(A, S) will return 5.
  6085.              See the file TESTUTIL.PAS
  6086.  
  6087.         See also:
  6088.  
  6089.  
  6090.  
  6091.  
  6092.  
  6093.  
  6094.  
  6095.  
  6096.  
  6097.  
  6098.  
  6099.                                   ShUtilPk  9-7
  6100.  
  6101.  
  6102.  
  6103.         ____________________________
  6104.         REPALL
  6105.  
  6106.         Declaration:
  6107.              procedure RepAll(S1, FS, SS : String; var S2 : string);
  6108.              function RepAllF(S1, FS, SS : string) : string;
  6109.  
  6110.         Purpose:
  6111.              In string S1 replace all occurrences of FS with SS
  6112.  
  6113.         Comments:
  6114.  
  6115.         Examples:
  6116.              See the file TESTUTIL.PAS
  6117.  
  6118.         See also:
  6119.              DelAll
  6120.  
  6121.  
  6122.         ____________________________
  6123.         SEARCHENVIRONMENT
  6124.  
  6125.         Declaration:
  6126.              function SearchEnvironment(Code : String) : String;
  6127.  
  6128.         Purpose:
  6129.              Searches the environment space for "CODE" and returns the
  6130.         corresponding string.
  6131.  
  6132.         Comments:
  6133.              If the CODE string has not been set with a SET statement,
  6134.         the function will return an empty string.
  6135.  
  6136.         Examples:
  6137.              If the DOS command
  6138.                                  SET GORP=FooBaz
  6139.         has been executed, then
  6140.                             SearchEnvironment('GORP')
  6141.         will return
  6142.                                      'FooBaz'
  6143.  
  6144.         See also:
  6145.  
  6146.  
  6147.  
  6148.  
  6149.  
  6150.  
  6151.  
  6152.  
  6153.  
  6154.  
  6155.  
  6156.  
  6157.                                   ShUtilPk  9-8
  6158.  
  6159.  
  6160.  
  6161.         ____________________________
  6162.         STARSTRING
  6163.  
  6164.         Declaration:
  6165.              function StarString(Pattern, Target : String) : Boolean;
  6166.  
  6167.         Purpose:
  6168.              This function performs a generalization of the wildcard
  6169.         string matching usually performed by DOS.
  6170.  
  6171.         Comments:
  6172.              The mask is presented in Pattern, and the string to be
  6173.         scanned is presented in Target. The function will return TRUE or
  6174.         FALSE as the target does or does not match the mask.
  6175.  
  6176.              A '*' wild card can be placed anywhere within the mask, and
  6177.         will represent its usual 'zero or more of any characters'. Scan-
  6178.         ning will not be terminated at that point, however, but will con-
  6179.         tinue. Thus, '*B*EFG' will match 'ABCDEFG', but '*B*EGF' will
  6180.         not. Similarly, '*ABC*' will match, but '*ABC' will not.
  6181.  
  6182.              A '?' wild card can also be placed anywhere within the mask,
  6183.         and will also represent its usual 'one occurrance of any char-
  6184.         acter'.
  6185.  
  6186.         Examples:
  6187.                   StarString('*B*EFG', 'ABCDEFG')
  6188.                                                             returns TRUE.
  6189.  
  6190.                   StarString('*B*EGF', 'ABCDEFG')
  6191.                                                             returns FALSE
  6192.                            but would return TRUE using the DOS algorithm.
  6193.              See the file TESTUTIL.PAS
  6194.  
  6195.         See also:
  6196.  
  6197.  
  6198.  
  6199.  
  6200.  
  6201.  
  6202.  
  6203.  
  6204.  
  6205.  
  6206.  
  6207.  
  6208.  
  6209.  
  6210.  
  6211.  
  6212.  
  6213.  
  6214.  
  6215.                                   ShUtilPk  9-9
  6216.  
  6217.  
  6218.  
  6219.         ____________________________
  6220.         UNIQUEFILENAME
  6221.  
  6222.         Declaration:
  6223.              function UniqueFileName
  6224.                       (Path : String; AddExt : Boolean) : string;
  6225.  
  6226.         Purpose:
  6227.              Returns a file name which will be unique in the directory
  6228.         specified by PATH.
  6229.  
  6230.         Comments:
  6231.              On return, the file name will be appended to PATH to give a
  6232.         fully qualified path.
  6233.  
  6234.              If AddExt is TRUE, an extension of .$$$ will be appended,
  6235.         else only the file name will be returned. In either case, the
  6236.         returned entity is guaranteed to be unique.
  6237.  
  6238.         Examples:
  6239.              See the file TESTUTIL.PAS
  6240.  
  6241.         See also:
  6242.  
  6243.  
  6244.         ____________________________
  6245.         WHOAMI
  6246.  
  6247.         Declaration:
  6248.              function WhoAmI : String;
  6249.  
  6250.         Purpose:
  6251.              Returns the fully qualified path to the currently executing
  6252.         file.
  6253.  
  6254.         Comments:
  6255.              Can be used with DOS 3.x or above, ONLY.
  6256.  
  6257.         Examples:
  6258.              See the file TESTUTIL.PAS
  6259.  
  6260.         See also:
  6261.  
  6262.  
  6263.  
  6264.  
  6265.  
  6266.  
  6267.  
  6268.  
  6269.  
  6270.  
  6271.  
  6272.  
  6273.                                   ShUtilPk  9-10
  6274.                                                          03/25/92 01:54pm
  6275.  
  6276.  
  6277.  
  6278.  
  6279.  
  6280.  
  6281.  
  6282.  
  6283.  
  6284.                                       Index
  6285.  
  6286.  
  6287.                B                           DelAll............. 9-3
  6288.                BetwS.............. 9-2     DelAllF............ 9-3
  6289.                BetwU.............. 9-2     DelimSet........... 9-1
  6290.                                            DelimSetType....... 9-1
  6291.                C                           dlAppend........... 7-4
  6292.                C2P................ 3-3     dlCount............ 7-4
  6293.                C2PF............... 3-3     dlFree............. 7-5
  6294.                CAbs............... 3-4     dlGetCurrent....... 7-6
  6295.                CAbsF.............. 3-4     dlGetFirst......... 7-6
  6296.                CAdd............... 3-4     dlGetLast.......... 7-7
  6297.                CAddF.............. 3-4     dlGetNext.......... 7-7
  6298.                CConj.............. 3-5     dlGetPrev.......... 7-8
  6299.                CConjF............. 3-5     dlLessFunc......... 7-3
  6300.                CDiv............... 3-5     dlList............. 7-3
  6301.                CDivF.............. 3-5     dlListInit......... 7-9
  6302.                CharSet............ 2-2     dlNode............. 7-2
  6303.                CheckOff........... 6-2     dlNodePtr.......... 7-2
  6304.                CheckOn............ 6-2     dlPop............. 7-10
  6305.                ClClose............ 2-3     dlPush............ 7-11
  6306.                ClInit............. 2-3     dlPut............. 7-12
  6307.                ClParse............ 2-4     dlPutPrev......... 7-12
  6308.                Cmp2Str............ 3-6     dlPutSorted....... 7-13
  6309.                CmplxError......... 3-6     dlSpaceUsed....... 7-14
  6310.                CmpP2Str........... 3-7     DoW................ 5-3
  6311.                CmpP2StrD.......... 3-7
  6312.                CMul............... 3-8     G
  6313.                CMulF.............. 3-8     GetNext............ 9-4
  6314.                Color Constants........     GetNextF........... 9-4
  6315.                              1-1 - 1-3     GetSwitch.......... 2-6
  6316.                ColorName.......... 1-5     Greg2ANSI.......... 5-3
  6317.                Complex............ 3-3     Greg2JDate......... 5-4
  6318.                ComplexBaseType.... 3-3     Greg2JDN........... 5-4
  6319.                ComplexElement..... 3-3     Greg2Str........... 5-6
  6320.                CpPwrR............. 3-8     GregType........... 5-2
  6321.                CpPwrRF............ 3-8
  6322.                CrcCalc............ 4-2     H
  6323.                CrcCopy............ 4-3     HaltMsg............ 6-3
  6324.                CSub............... 3-9     HEX................ 9-4
  6325.                CSubF.............. 3-9     HiWord............. 9-5
  6326.  
  6327.                D                           I
  6328.                DayStr............. 5-2     Im................. 3-3
  6329.  
  6330.  
  6331.  
  6332.                                      index-i
  6333.  
  6334.  
  6335.  
  6336.                IntVal............. 2-2     lsInsert.......... 8-17
  6337.                                            lsInsertF......... 8-17
  6338.                J                           lsInsertStr....... 8-17
  6339.                JDate2Greg......... 5-5     lsInsertStrF...... 8-17
  6340.                JDN2ANSI........... 5-5     lsIoff............ 8-14
  6341.                JDN2Greg........... 5-6     lsIon............. 8-15
  6342.                JDN2Str............ 5-7     lsIoResult........ 8-16
  6343.                                            lsLeftPad......... 8-18
  6344.                L                           lsLeftPadCh....... 8-19
  6345.                LI................. 9-6     lsLeftPadChF...... 8-19
  6346.                LongString......... 8-3     lsLeftPadF........ 8-18
  6347.                LongStringType..... 8-3     lsLength.......... 8-20
  6348.                LoWord............. 9-6     lsLocase.......... 8-20
  6349.                lsCenter........... 8-5     lsLocaseF......... 8-20
  6350.                lsCenterCh......... 8-5     lsLongString2Str.. 8-21
  6351.                lsCenterChF........ 8-5     lsPad............. 8-21
  6352.                lsCenterF.......... 8-5     lsPadCh........... 8-22
  6353.                lsCharStr.......... 8-6     lsPadChF.......... 8-22
  6354.                lsCharStrF......... 8-6     lsPadF............ 8-21
  6355.                lsComp............. 8-7     lsPos............. 8-22
  6356.                lsCompType......... 8-3     lsPosSet.......... 8-23
  6357.                lsConcat........... 8-7     lsPosStr.......... 8-22
  6358.                lsConcatF.......... 8-7     lsPosStrUC........ 8-22
  6359.                lsConcatLs2Str..... 8-7     lsPosUC........... 8-22
  6360.                lsConcatLs2StrF.... 8-7     lsReadLn.......... 8-24
  6361.                lsConcatStr2Ls..... 8-7     lsRepAll.......... 8-24
  6362.                lsConcatStr2LsF.... 8-7     lsRepAllF......... 8-24
  6363.                lsCopy............. 8-8     lsRepAllStr....... 8-24
  6364.                lsCopyF............ 8-8     lsRepAllStrF...... 8-24
  6365.                lsCount............ 8-9     lsRepAllStrUC..... 8-24
  6366.                lsCountStr......... 8-9     lsRepAllStrUCF.... 8-24
  6367.                lsCountStrUC....... 8-9     lsRepAllUC........ 8-24
  6368.                lsCountUC.......... 8-9     lsRepAllUCF....... 8-24
  6369.                lsDelAll.......... 8-10     lsSizeOf.......... 8-25
  6370.                lsDelAllF......... 8-10     lsStr2LongString.. 8-26
  6371.                lsDelAllStr....... 8-10     lsStr2LongStringF. 8-26
  6372.                lsDelAllStrF...... 8-10     lsTransfer........ 8-27
  6373.                lsDelAllStrUC..... 8-10     lsTrim............ 8-28
  6374.                lsDelAllStrUCF.... 8-10     lsTrimF........... 8-28
  6375.                lsDelAllUC........ 8-10     lsTrimLead........ 8-28
  6376.                lsDelAllUCF....... 8-11     lsTrimLeadF....... 8-28
  6377.                lsDelete.......... 8-12     lsTrimLeadSet..... 8-29
  6378.                lsDeleteF......... 8-12     lsTrimLeadSetF.... 8-29
  6379.                lsDelimSet......... 8-3     lsTrimSet......... 8-30
  6380.                lsDelimSetType..... 8-3     lsTrimSetF........ 8-30
  6381.                lsDispose......... 8-12     lsTrimTrail....... 8-29
  6382.                lsGetNext......... 8-13     lsTrimTrailF...... 8-29
  6383.                lsGetNextF........ 8-13     lsTrimTrailSet.... 8-30
  6384.                lsGetNextStr...... 8-13     lsTrimTrailSetF... 8-30
  6385.                lsGetNextStrF..... 8-13     lsUpcase.......... 8-31
  6386.                lsInit............ 8-13     lsUpcaseF......... 8-31
  6387.  
  6388.  
  6389.  
  6390.                                     index-ii
  6391.  
  6392.  
  6393.  
  6394.                lsWriteLn......... 8-31     slGetFirst......... 7-6
  6395.                                            slGetLast.......... 7-7
  6396.                M                           slGetNext.......... 7-7
  6397.                MaxLongString...... 8-4     slList............. 7-3
  6398.                MonthStr........... 5-2     slListInit......... 7-9
  6399.                                            slNode............. 7-2
  6400.                N                           slNodePtr.......... 7-2
  6401.                NotFound........... 8-4     slPop............. 7-10
  6402.                Now................ 5-7     slPush............ 7-11
  6403.                Now2Time........... 5-7     slPut............. 7-12
  6404.                NowStr............. 5-8     slSpaceUsed....... 7-14
  6405.                                            SSM2Time........... 5-8
  6406.                O                           SSM2TimeStr........ 5-9
  6407.                Orientation........ 1-3     StarString......... 9-9
  6408.                                            StartingAttr....... 9-1
  6409.                P                           StartingMode....... 9-1
  6410.                P2C................ 3-9     StrVal............. 2-2
  6411.                P2CF............... 3-9     SwRec.............. 2-2
  6412.                Pmod............... 9-7     SwVal.............. 2-2
  6413.                PopSwitch.......... 2-6
  6414.                PosSet............. 9-7     T
  6415.                                            Time2SSM........... 5-9
  6416.                R                           Time2TimeStr...... 5-10
  6417.                Re................. 3-3     TimeType........... 5-2
  6418.                ReadSwCh........... 2-7     Today............. 5-10
  6419.                RealVal............ 2-2     Today2ANSI........ 5-11
  6420.                RepAll............. 9-8     Today2Greg........ 5-11
  6421.                RepAllF............ 9-8     TodayStr.......... 5-12
  6422.                RingSize........... 8-3
  6423.                RunErrorMsg........ 6-3     U
  6424.                RxC............... 3-10     UniqueFileName..... 9-9
  6425.                RxCF.............. 3-10
  6426.                                            V
  6427.                S                           ValueType.......... 2-2
  6428.                SearchEnvironment.. 9-8     VtInt.............. 2-2
  6429.                SelectColors....... 1-3     VtReal............. 2-2
  6430.                SetSwCh............ 2-8     VtStr.............. 2-2
  6431.                slAppend........... 7-4
  6432.                slCount............ 7-4     W
  6433.                slFree............. 7-5     WhoAmI............ 9-10
  6434.                slGetCurrent....... 7-6
  6435.  
  6436.  
  6437.  
  6438.  
  6439.  
  6440.  
  6441.  
  6442.  
  6443.  
  6444.  
  6445.  
  6446.  
  6447.  
  6448.                                     index-iii
  6449.  
  6450.